2017-02-10 53 views
0

這裏有一個基本佈局,但ScrollView內的LinearLayout與父高度不匹配。子佈局的高度與父佈局不匹配

<LinearLayout 
    . 
    . 
    android:layout_width = "match_parent" 
    android:layout_height = "match_parent" 
    android:orientation = "vertical" 
    . 
    .> 
    <EditText 
    . 
    ./> 

    <Button 
    . 
    ./> 

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

     <LinearLayout 
      android:id = "@+id/layoutWeb" 
      android:layout_width = "match_parent" 
      android:layout_height = "match_parent" 
      android:orientation = "vertical"> 

      <ListView 
       android:id = "@+id/listWeb" 
       android:layout_width = "match_parent" 
       android:layout_height = "match_parent"> 

      </ListView> 

     </LinearLayout> 

    </ScrollView> 

</LinearLayout> 

IDE建議將線性佈局的(id = layoutWeb)高度更改爲wrap_parent。我選擇下面的截圖線性佈局,但它的高度不匹配父 Screenshot

+1

永遠不要把ListView放入ScrollView,並且第一個LinearLayout是否包含任何填充? –

+0

我剛剛意識到那太愚蠢了。但爲什麼它不工作? –

+0

match_parent在ScrollView根目錄中不起作用。你也應該更新一個滾動到另一個(ListView到ScrollView)。 –

回答

3
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 


<LinearLayout 
    android:id="@+id/layoutWeb" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <ListView 
      android:id="@+id/listWeb" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
</LinearLayout> 

試試這個代碼。對於listview你不需要使用scrollview。它已經滾動

+0

謝謝。我現在明白了 –