2013-06-02 36 views
8

Tôi đột nhiên gặp vấn đề mà Scrollview mở rộng ra phía dưới màn hình để ngay cả khi bạn cuộn hết cỡ, nó không hiển thị tất cả nội dung của nó. XML là:Scrollview mở rộng ra ngoài phần dưới màn hình

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFFFF"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="15dp" 
     android:background="#FFBBBBBB" 
     android:orientation="vertical" > 
     <View 
      android:layout_width="100dp" 
      android:layout_height="300dp" 
      android:layout_margin="15dp" 
      android:layout_gravity="center_horizontal" 
      android:background="#FFDDDDFF"/> 
     <View 
      android:layout_width="100dp" 
      android:layout_height="300dp" 
      android:layout_margin="15dp" 
      android:layout_gravity="center_horizontal" 
      android:background="#FFDDDDFF"/> 
    </LinearLayout> 
</ScrollView> 

Nó không đơn giản hơn thế. Một khi bạn đã cuộn tất cả các con đường xuống (như được chỉ ra bởi hình dạng của các cuộn), bạn sẽ thấy bên lề trắng đáy nhưng thay vì đây là những gì nó trông giống như:

bottom of the scrollview

Hãy so sánh với đỉnh:

top of the scrollview

Phần dưới trông giống như trên cùng, chỉ đảo ngược. Điều này xảy ra trong trình mô phỏng, trên các thiết bị thực và trong hầu hết mọi phiên bản Android mà tôi đã thử. Tôi đang thua lỗ về những gì tôi đang làm sai (nếu có ...).

Vui lòng không đoán và không chụp từ hông! Chỉ các câu trả lời được kiểm tra. Tôi đã lãng phí đủ thời gian cho chuyện này rồi. Cảm ơn.

Trả lời

0

thử đặt đệm ở cuối chế độ xem cuộn, để bạn thấy một đường màu trắng ở dưới cùng - chế độ xem của bạn thực sự cuộn xuống hết cỡ, tôi đã thử với mã này và kết quả là:

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

    android:background="#FFFFFFFF" 
    android:padding="5dp" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="15dp" 
    android:background="#FFBBBBBB" 
    android:orientation="vertical" > 

    <View 
     android:layout_width="100dp" 
     android:layout_height="1500dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="15dp" 
     android:background="#FFDDDDFF" /> 

    <View 
     android:layout_width="100dp" 
     android:layout_height="300dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="15dp" 
     android:background="#FFDDDDFF" /> 

    <View 
     android:layout_width="100dp" 
     android:layout_height="10dp" 
     android:layout_gravity="center_horizontal" 
     android:layout_margin="15dp" 
     android:background="#FF00FF00" /> 
</LinearLayout> 

enter image description here

+0

Khi thực sự có thể cố gắng để chơi trò chơi như thế nhưng đó là một hack, không phải là một giải pháp đúng. – olefevre

+0

PS: Thấy một số màu trắng ở phía dưới không phải là kết thúc! Vì có một lề trên tất cả các mặt của LinearLayout, nhìn thấy lề dưới là dấu hiệu cho thấy bạn đã thực sự đạt đến đáy; đó là tất cả. – olefevre

7

Sau lãng phí nhiều thời gian trong hẻm chết tôi cuối cùng đã được đưa đi đúng hướng bởi other SO thread này: vấn đề là bên lề bố trí trên LinearLayout. Rõ ràng ScrollView không thích điều đó, cũng giống như nó không giống như con của nó là trung tâm (một vấn đề được nhiều người khác gắn cờ nhưng không phải vấn đề của tôi ở đây) và ai biết điều gì khác. Rất choosy widget. Đó là vấn đề như thế này khiến tôi cân nhắc lại cam kết của mình với Android: nó quá tốn thời gian so với các nền tảng thay thế và, ngay cả khi bạn thích thử thách, thời gian là tiền bạc.

Dù sao, vì lợi ích của những người sẽ thất bại ở đây sau, đây là cách trình bày bên lề của bố cục bị hỏng (phiên bản đơn giản hơn ở bên trái) và bên trái. Bí quyết là để mô phỏng lề verboten với đệm trên một container thêm.

<?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="wrap_content" 
    android:background="#00FFFF" 
    android:orientation="horizontal" 
    android:baselineAligned="false"> 
    <ScrollView   
     android:layout_width="0dp" 
     android:layout_weight="1"  
     android:layout_height="match_parent" 
     android:background="#FFFFFFFF"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="15dp" 
      android:background="#FFBBBB22" 
      android:orientation="vertical"> 
      <View 
       android:layout_width="100dp" 
       android:layout_height="1000dp" 
       android:layout_margin="15dp" 
       android:layout_gravity="center_horizontal" 
       android:background="#FFDDDDFF"/> 
     </LinearLayout> 
    </ScrollView> 
    <View 
     android:layout_width="1dp" 
     android:layout_height="match_parent" 
     android:background="#FF000000"/> 
    <ScrolllView 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="match_parent" 
     android:background="#FFFFFFFF"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="15dp" 
      android:background="#FFFFFF" 
      android:orientation="vertical"> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#FFBBBB22" 
       android:orientation="vertical"> 
       <View 
        android:layout_width="100dp" 
        android:layout_height="1000dp" 
        android:layout_margin="15dp" 
        android:layout_gravity="center_horizontal" 
        android:background="#FFDDDDFF"/> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
0

Chỉ cần cố gắng đặt LinearLayout bên trong một khác Như thế này:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFFFF"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="15dp" 
      android:background="#FFBBBBBB" 
      android:orientation="vertical"> 

      <View 
       android:layout_width="100dp" 
       android:layout_height="300dp" 
       android:layout_gravity="center_horizontal" 
       android:layout_margin="15dp" 
       android:background="#FFDDDDFF" /> 

      <View 
       android:layout_width="100dp" 
       android:layout_height="300dp" 
       android:layout_gravity="center_horizontal" 
       android:layout_margin="15dp" 
       android:background="#FFDDDDFF" /> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 
Các vấn đề liên quan