【问题标题】:Height of child layout not matching parent layout子布局的高度与父布局不匹配
【发布时间】:2017-02-10 10:40:15
【问题描述】:

我这里有一个基本的布局,但是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。我在下面的屏幕截图中选择了线性布局,但它的高度与父级不匹配

【问题讨论】:

  • 永远不要把 ListView 放在 ScrollView 里面,第一个 LinearLayout 是否包含任何填充?
  • 我才意识到这太愚蠢了。但是为什么不行呢?
  • match_parent 在 ScrollView 根目录中不起作用。此外,您应该更新将一个滚动条放入另一个滚动条(ListView 放入 ScrollView)。
  • ScrollView 内的ListView 与父布局高度不匹配,您可以使用回收站视图或参考此链接stackoverflow.com/questions/21264951/…

标签: android android-layout


【解决方案1】:
<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>

试试这个代码。对于列表视图,您不需要使用滚动视图。它已经可以滚动了

【讨论】:

  • 谢谢。我现在明白了
猜你喜欢
  • 2015-12-15
  • 2019-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多