2012-01-29 39 views
13

Tôi có cách bố trí như sau:RelativeLayout - Cuộn xuống

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:id="@+navigate/RLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ABABAB" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textStyle="bold" 
     android:id="@+id/myid" 
     android:layout_centerHorizontal="true" 
     android:src="@drawable/myid" 
     android:layout_marginTop="15dp" />. 
    <RelativeLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/firstRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/myid" > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textStyle="bold|italic" 
     android:textColor="#000000" 
     android:id="@+id/hotelinfos" 
     android:layout_marginTop="10dp" 
     android:layout_marginLeft="10dp" 
     android:layout_below="@+id/myid" 
     android:layout_alignLeft="@+id/myid"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textStyle="bold" 
     android:textColor="#000000" 
     android:id="@+id/hotelname" 
     android:layout_below="@+id/hotelinfos" 
     android:layout_alignLeft="@+id/hotelinfos" 
     android:layout_marginTop="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/hoteladdress" 
     android:layout_below="@+id/hotelname" 
     android:layout_alignLeft="@+id/hotelname" 
     android:layout_marginTop="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:id="@+id/hotelphone" 
     android:layout_below="@+id/hoteladdress" 
     android:layout_alignLeft="@+id/hoteladdress" 
     android:layout_marginTop="10dp" 
     android:textColor="#12C" 
     android:textStyle="bold|italic" 
     android:onClick="onClick" 
     android:clickable="true" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#12C" 
     android:onClick="onClick" 
     android:clickable="true" 
     android:textStyle="bold|italic" 
     android:id="@+id/hotelemail" 
     android:layout_below="@+id/hotelphone" 
     android:layout_alignLeft="@+id/hotelphone" 
     android:layout_marginTop="10dp" 
     android:paddingBottom="10dp" /> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/picture" 
     android:layout_below="@+id/myid" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="10dp"  
     android:layout_marginTop="10dp"/> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/SecondRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/firstRectangle" > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:textStyle="bold|italic" 
     android:id="@+id/bookinginfos" 
     android:layout_below="@+id/firstRectangle" 
     android:layout_alignLeft="@+id/firstRectangle" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/pnr" 
     android:layout_below="@+id/bookinginfos" 
     android:layout_alignLeft="@+id/bookinginfos" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/segmentCode" 
     android:layout_below="@+id/pnr" 
     android:layout_alignLeft="@+id/pnr" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/checkin" 
     android:layout_below="@+id/segmentCode" 
     android:layout_alignLeft="@+id/segmentCode" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/checkout" 
     android:layout_below="@+id/checkin" 
     android:layout_alignLeft="@+id/checkin" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/nights"  
     android:layout_below="@+id/checkout" 
     android:layout_alignLeft="@+id/checkout" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/roomType" 
     android:layout_below="@+id/nights" 
     android:layout_alignLeft="@+id/nights" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/boardBasis" 
     android:layout_below="@+id/roomType" 
     android:layout_alignLeft="@+id/roomType" 
     android:layout_marginRight="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/paxNames" 
     android:layout_below="@+id/boardBasis" 
     android:layout_alignLeft="@+id/boardBasis" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:paddingBottom="10dp" /> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/thirdRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/SecondRectangle" > 
      <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:textStyle="bold|italic" 
     android:id="@+id/forHotel" 
     android:layout_below="@+id/SecondRectangle" 
     android:layout_alignLeft="@+id/SecondRectangle" 
     android:layout_marginLeft="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/supplierCode" 
     android:layout_below="@+id/forHotel" 
     android:layout_alignLeft="@+id/forHotel" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:paddingBottom="10dp"/> 
     </ScrollView> 

    </RelativeLayout> 
</RelativeLayout> 

Tôi muốn di chuyển trong cách bố trí này bởi vì phần cuối cùng của RelativeLayout không nhìn thấy được! Nhưng tôi không biết làm thế nào để làm điều đó. Tôi đã cố gắng thêm một scrollview nhưng tôi đã nhận lỗi: scrollview có thể lưu trữ chỉ có một con trực tiếp! Bạn có lời khuyên nào cho tôi không?

Cảm ơn trước sự giúp đỡ của bạn!

+0

bạn có thể cho chúng ta thấy tập tin xml của bạn với scrollview thêm, bởi vì theo như tôi thấy, nó sẽ hoạt động bằng cách sử dụng scrollview, có thể yo u chỉ cần thực hiện một giám sát – joni

Trả lời

41

ScrollView hy vọng một cái nhìn trẻ độc thân và trong cách bố trí của bạn, bạn có 2 TextView. Để thực hiện tác vụ ScrollView, bạn phải quấn TextView trong một ViewGroup như LinearLayout hoặc RelativeLayout.

đang được sửa đổi:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> 
<RelativeLayout 
    android:id="@+navigate/RLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ABABAB" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
// ... THE REST OF YOUR CODE 
</RelativeLayout> 
</ScrollView> 
+0

Hi slukian! Trong thực tế, tôi không chắc chắn rằng ScrollView là giải pháp phù hợp với tôi. Tôi muốn di chuyển trong relativeLayout khi người dùng chạm vào màn hình ... Tôi chỉ không biết cách thực hiện nó><" –

+0

@JohnSmith Tôi đã chỉnh sửa câu trả lời của mình để bạn có trong' ScrollView' cuối cùng 'RelativeLayout 'Tôi không hiểu những gì bạn đang cố gắng làm: di chuyển trong (chính xác như thế nào" di chuyển trong ") các relativeLayout (mà RelativeLayout?) Khi người dùng chạm vào màn hình. Bạn có thể giải thích? – Luksprog

+0

Vâng, người cuối cùng của tôi là ẩn (vì bố cục lớn hơn màn hình của điện thoại!) Và tôi không thể cuộn xuống ... Android không tự động làm điều đó? –

3

Hãy mã này đúng hơn bạn muốn cuộn để bắt đầu:

<ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 

Sau đó kết thúc với khi bạn muốn ngăn chặn nó.

3

scrollview chỉ có thể có con, đứa trẻ có thể là bất kỳ layout nào. Hãy ở trong LinearLayout hoặc RelativeLayout. Vì vậy, nó phải là một cái gì đó như thế này. <ScrollView><RelativeLayout></RelativeLayout></ScrollView>

Mã của bạn sẽ kết thúc như thế này

<RelativeLayout 
android:id="@+navigate/RLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#ABABAB" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 

<ScrollView> 
android:id="@+navigate/Scrollview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<RelativeLayout 
android:id="@+navigate/RLayout02" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 

> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textStyle="bold" 
    android:id="@+id/hcorpo" 
    android:layout_centerHorizontal="true" 
    android:src="@drawable/hcorpo" 
    android:layout_marginTop="15dp" />. 
<RelativeLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="10dp" 
    android:orientation="vertical" 
    android:id="@+id/firstRectangle" 
    android:background="@drawable/bg" 
    android:layout_below="@+id/hcorpo" > 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textStyle="bold|italic" 
    android:textColor="#000000" 
    android:id="@+id/hotelinfos" 
    android:layout_marginTop="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_below="@+id/hcorpo" 
    android:layout_alignLeft="@+id/hcorpo"/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textStyle="bold" 
    android:textColor="#000000" 
    android:id="@+id/hotelname" 
    android:layout_below="@+id/hotelinfos" 
    android:layout_alignLeft="@+id/hotelinfos" 
    android:layout_marginTop="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/hoteladdress" 
    android:layout_below="@+id/hotelname" 
    android:layout_alignLeft="@+id/hotelname" 
    android:layout_marginTop="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:id="@+id/hotelphone" 
    android:layout_below="@+id/hoteladdress" 
    android:layout_alignLeft="@+id/hoteladdress" 
    android:layout_marginTop="10dp" 
    android:textColor="#12C" 
    android:textStyle="bold|italic" 
    android:onClick="onClick" 
    android:clickable="true" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#12C" 
    android:onClick="onClick" 
    android:clickable="true" 
    android:textStyle="bold|italic" 
    android:id="@+id/hotelemail" 
    android:layout_below="@+id/hotelphone" 
    android:layout_alignLeft="@+id/hotelphone" 
    android:layout_marginTop="10dp" 
    android:paddingBottom="10dp" /> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/picture" 
    android:layout_below="@+id/hcorpo" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="10dp"  
    android:layout_marginTop="10dp"/> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="10dp" 
    android:orientation="vertical" 
    android:id="@+id/SecondRectangle" 
    android:background="@drawable/bg" 
    android:layout_below="@+id/firstRectangle" > 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:textStyle="bold|italic" 
    android:id="@+id/bookinginfos" 
    android:layout_below="@+id/firstRectangle" 
    android:layout_alignLeft="@+id/firstRectangle" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/pnr" 
    android:layout_below="@+id/bookinginfos" 
    android:layout_alignLeft="@+id/bookinginfos" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/segmentCode" 
    android:layout_below="@+id/pnr" 
    android:layout_alignLeft="@+id/pnr" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/checkin" 
    android:layout_below="@+id/segmentCode" 
    android:layout_alignLeft="@+id/segmentCode" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/checkout" 
    android:layout_below="@+id/checkin" 
    android:layout_alignLeft="@+id/checkin" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/nights"  
    android:layout_below="@+id/checkout" 
    android:layout_alignLeft="@+id/checkout" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/roomType" 
    android:layout_below="@+id/nights" 
    android:layout_alignLeft="@+id/nights" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/boardBasis" 
    android:layout_below="@+id/roomType" 
    android:layout_alignLeft="@+id/roomType" 
    android:layout_marginRight="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/paxNames" 
    android:layout_below="@+id/boardBasis" 
    android:layout_alignLeft="@+id/boardBasis" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" 
    android:paddingBottom="10dp" /> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_margin="10dp" 
    android:orientation="vertical" 
    android:id="@+id/thirdRectangle" 
    android:background="@drawable/bg" 
    android:layout_below="@+id/SecondRectangle" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:textStyle="bold|italic" 
    android:id="@+id/forHotel" 
    android:layout_below="@+id/SecondRectangle" 
    android:layout_alignLeft="@+id/SecondRectangle" 
    android:layout_marginLeft="10dp" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="10dp" 
    android:textColor="#000000" 
    android:id="@+id/supplierCode" 
    android:layout_below="@+id/forHotel" 
    android:layout_alignLeft="@+id/forHotel" 
    android:layout_marginTop="10dp" 
    android:layout_marginRight="10dp" 
    android:paddingBottom="10dp"/> 


</RelativeLayout> 
</RelativeLayout> 

</ScrollView> 

</RelativeLayout> 
3

của bạn cuối cùng RelativeLayout

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/thirdRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/SecondRectangle" > 
      <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:textStyle="bold|italic" 
     android:id="@+id/forHotel" 
     android:layout_below="@+id/SecondRectangle" 
     android:layout_alignLeft="@+id/SecondRectangle" 
     android:layout_marginLeft="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/supplierCode" 
     android:layout_below="@+id/forHotel" 
     android:layout_alignLeft="@+id/forHotel" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:paddingBottom="10dp"/> 
     </ScrollView> 

    </RelativeLayout> 

nên trông như thế này thay vì:

<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"> 
<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     android:id="@+id/thirdRectangle" 
     android:background="@drawable/bg" 
     android:layout_below="@+id/SecondRectangle" > 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:textStyle="bold|italic" 
     android:id="@+id/forHotel" 
     android:layout_below="@+id/SecondRectangle" 
     android:layout_alignLeft="@+id/SecondRectangle" 
     android:layout_marginLeft="10dp" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="10dp" 
     android:textColor="#000000" 
     android:id="@+id/supplierCode" 
     android:layout_below="@+id/forHotel" 
     android:layout_alignLeft="@+id/forHotel" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="10dp" 
     android:paddingBottom="10dp"/> 

    </RelativeLayout> 
</ScrollView> 
Các vấn đề liên quan