2013-06-02 51 views
8

我突然出現了滾動查看超出屏幕底部的問題,因此即使您一直向下滾動,它也不會顯示其所有內容。 XML是:滾動查看延伸到屏幕底部以外

<?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> 

它沒有比這更簡單。一旦你滾動一路下跌(由滾動條的形狀所示),你應該看到底部白邊,而是這是什麼樣子:

bottom of the scrollview

與頂級比較:

top of the scrollview

底部應該看起來像頂部,只能顛倒。這發生在模擬器,真實設備以及幾乎所有我試過的Android版本中。我對我在做什麼錯誤感到不知所措(如果有的話......)。

請不要猜測,不要從臀部拍攝!只測試了答案。現在我已經浪費了足夠的時間。謝謝。

回答

0

嘗試在滾動視圖的底部填充填充以便您在底部看到一條白線 - 您的視圖確實會一直向下滾動,我使用此代碼嘗試過,結果如下:

<?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

一旦確實可以嘗試玩這樣的遊戲,但它是一個黑客,而不是一個真正的解決方案。 – olefevre

+0

PS:在底部看到一些白色,本身並不是目的!由於LinearLayout的所有邊都有餘量,所以看到下邊距是您真正達到底部的信號;就這樣。 – olefevre

7

死小巷浪費太多的時間後,我終於把正確的軌道上這個other SO thread:這個問題是對的LinearLayout佈局保證金。顯然ScrollView不喜歡這樣,就像它不喜歡它的孩子被集中(許多其他人標記的問題,但不是我的問題在這裏),誰知道還有什麼。非常挑剔的部件。像這樣的問題讓我重新考慮了我對Android的承諾:相對於其他平臺而言,這太耗時了,即使您喜歡挑戰,時間也是金錢。

無論如何,爲了讓那些稍後會在這裏翻牌的人的利益,這裏是一個左側和右側工作的破碎布局(一個更簡單的版本)的並行演示。訣竅是在額外的容器上使用填充來模擬具體情況。

<?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

剛剛嘗試把裏面的LinearLayout另一個 像這樣:

<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>