2012-02-17 25 views
31

Tôi muốn thực hiện điều này: Một ScrollView có chứa nhiều phần tử (ImageViews, TextViews, EditTexts vv) và sau đó sau khi ScrollView một số nút (đó là tùy chỉnh ImageViews) xuất hiện luôn chính xác dưới cùng của màn hình.Android ScrollView và các nút ở dưới cùng của màn hình

Nếu tôi sử dụng thuộc tính android: fillViewport = "true", thì nếu các phần tử của ScrollView quá lớn để vừa với kích thước màn hình thì các nút sẽ không nhìn thấy được. Nếu tôi sử dụng thuộc tính android: Weight = 1 thì ScrollView chỉ nhận được 50% màn hình khi màn hình lớn và có thể vừa với (tôi muốn các nút chiếm tỷ lệ nhỏ, khoảng 10%). Nếu tôi đặt android: Weight thành giá trị lớn hơn thì các nút xuất hiện rất nhỏ.

Vui lòng trợ giúp! Có lẽ nó là một cái gì đó đơn giản mà tôi bỏ qua nhưng tôi đã đập đầu của tôi trong nhiều giờ!

+0

Hãy hiển thị các file layout –

Trả lời

72

Chỉ cần tạo và thử nghiệm nó. Có vẻ như bạn muốn.

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <LinearLayout 
      android:id="@+id/buttons" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="center" 
      android:layout_alignParentBottom="true"> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Custom Button1"/> 
     <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Custom Button2"/> 
    </LinearLayout> 

    <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@id/buttons"> 
     <!--Scrollable content here--> 
     <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical">     
      <TextView 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="test text" 
        android:textSize="40dp"/> 
     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 
+0

đó làm việc tuyệt vời! Cảm ơn bạn! – george

+0

Tôi gặp vấn đề tương tự. Làm việc tốt với giải pháp này – zolio

+0

Khi ScrollView lấp đầy, nó sẽ không ghi đè lên các nút? – FractalBob

2

scrollview không thể vừa với màn hình bởi vì bạn đặt nó trên một bố trí tuyến tính, vì vậy tuyến tính phù hợp bố trí trong màn hình,

chỉ cố gắng làm cho scrollview như elemen gốc trên layout xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <!-- Here you can put some XML stuff and BOOM! your screen fit to scrollview --> 

    </LinearLayout> 
</ScrollView> 
3

Điều này phù hợp với tôi. Đặt khung nhìn cuộn với trọng số 1. Đặt tất cả các tiện ích khác sau chế độ xem cuộn trong bố cục. Chế độ xem cuộn sẽ phát triển đủ để không chặn phần còn lại.

Widgets in scroll view and rest at bottom

9
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hello World" 
      /> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hallo Welt" 
      />  
     </LinearLayout> 
    </ScrollView> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0"> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Go next page" 
      android:layout_alignParentRight="true" /> 
    </RelativeLayout> 

</LinearLayout> 
+0

hi am có bố trí với headder và scrolview của các lĩnh vực đầu vào và footer khi bàn phím đang đến mà footer cũng di chuyển up.how để sửa chữa footer ở bottom.please giúp tôi – Harsha

+0

Nó làm việc tôi đã đấu tranh để tìm giải pháp cho quá khứ 3 giờ. – chanakya

Các vấn đề liên quan