2015-09-19 58 views
-1

我想垂直设置两个Listviews。
我希望它们分别是垂直屏幕长度的40%和60%。有两个ListViews的布局权重

下面是代码:

<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需要所有的屏幕。

我也尝试删除嵌入两个ListViews的LinearLayout,但它也没有工作。 我也试过用android:layout_height =“wrap_content”在两个Listviews中都没有工作。

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

关于如何解决它的任何想法?

回答

0

这种布局将工作:

<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继承