【问题标题】:How to have 2 Listviews with each taking 50% and one starting empty and increasing in size.如何拥有 2 个列表视图,每个列表视图占 50%,一个开始为空并增加大小。
【发布时间】:2014-11-18 05:42:01
【问题描述】:

我需要在一个垂直的 LinearLayout 中有 2 个 Listview,每个 Listview 占据屏幕的 50%。我通过将 Listview 的权重设置为 50 每个 0.5 来实现这一点。

<LinearLayout
   android:layout_weight="1"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">
   <ListView
        android:id="@+id/searchResultSelection"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:divider="@null"
        />
    <ListView
        android:id="@+id/searchResultList"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:layout_marginTop="10dp"
        />
  </LinearLayout>

问题是顶部的 Listview 一开始是空的,而底部的通常占据整个屏幕。我想要的是底部从 100% 开始,每次将项目添加到顶部添加时,顶部会增加,而底部会减少,直到顶部的高度达到 50%。

谢谢

【问题讨论】:

    标签: android listview android-linearlayout


    【解决方案1】:

    试试这个:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <ListView
                android:id="@+id/searchResultSelection"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_above="@+id/dummy"
                android:divider="@null"
                 />
    
            <View 
                android:id="@+id/dummy"
                android:layout_width="0dip"
                android:layout_height="0dip"
                android:layout_centerVertical="true"
                />
            <ListView
                android:id="@+id/searchResultList"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/searchResultSelection"
                android:layout_marginTop="10dp" />
    
        </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-11
      • 2020-02-07
      • 2018-07-08
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多