【问题标题】:Layout weight with two ListViews具有两个 ListView 的布局权重
【发布时间】:2015-09-19 23:53:36
【问题描述】:

我想要两个垂直设置的列表视图。
我希望它们分别是垂直屏幕长度的 40% 和 60%。

代码如下:

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

<LinearLayout
  android:layout_weight="0.4" 
  android:layout_width="match_parent"
  android:layout_height="0dp">
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>
<LinearLayout
    android:layout_weight="0.6"
    android:layout_width="match_parent"
    android:layout_height="0dp">

     <ExpandableListView
        android:id="@+id/listEvents"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />
</LinearLayout>
</LinearLayout>

但这不起作用。
第一个 ListView 占据整个屏幕。

我也尝试删除嵌入两个 ListView 的 LinearLayout,但它也不起作用。 我还尝试在两个 Listviews 中使用 android:layout_height="wrap_content" 并且没有工作。

如果我将屏幕旋转到横向并再次返回端口后,它可以工作。
第一个实例创建失败。

你知道如何解决吗?

【问题讨论】:

    标签: android android-linearlayout android-layout-weight


    【解决方案1】:

    此布局将起作用:

    <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical"
         >
         <ListView
             android:id="@+id/lvwView"
             android:layout_width="match_parent"
             android:layout_height="0dp"
             android:layout_weight="0.4"
         />
         <ExpandableListView
            android:id="@+id/elvEvents"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.6"
        />
    </LinearLayout>
    

    只是不要继承来自ListActivityListFragment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-22
      相关资源
      最近更新 更多