【问题标题】:Why height of the list view is Full size?为什么列表视图的高度是全尺寸?
【发布时间】:2021-06-24 05:12:56
【问题描述】:

我希望列表视图显示在文本视图下方。 但是,文本视图不可见,只有列表视图以全尺寸显示。我该如何解决?

<?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:background="@color/white"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView21"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:gravity="center"
        android:text="채팅"
        android:textColor="#000000"
        android:textSize="20sp" />

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

【问题讨论】:

    标签: java android android-studio listview scroll


    【解决方案1】:

    你应该在列表视图中设置 layout_height = "wrap_content":

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

    【讨论】:

      【解决方案2】:

      这是因为在 ListView 中您使用的是 android:layout_height="match_parent

      您可以通过多种方式做到这一点,例如,您可以使用 android:layout_weight 属性。这个属性根据它应该在屏幕上占据多少空间来为视图分配一个“重要性”值。较大的权重值允许它扩展以填充父视图中的任何剩余空间。

      类似:

      <LinearLayout>
       
             <TextView
               ../>
      
             <ListView
                  android:layout_weight="1"
                  .../>
      
      </LinearLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-22
        • 2011-06-02
        • 2012-03-19
        • 1970-01-01
        • 2021-08-14
        相关资源
        最近更新 更多