【问题标题】:TextView above two ListViews两个ListView之上的TextView
【发布时间】:2014-03-25 09:22:41
【问题描述】:

我想在我的两个 ListView 上方有一个 TextView。这是我的 xml 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:baselineAligned="false"
    android:orientation="horizontal"
    android:layout_height="match_parent" 
    android:layout_width="match_parent">


<TextView 
    android:id="@+id/statusBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Test" />

<LinearLayout
    android:layout_weight="1" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"
    >

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

</LinearLayout>


<LinearLayout 
    android:layout_weight="1" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent">

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

</LinearLayout>

</LinearLayout>

在我添加 TextView 之前一切正常。现在只有 TextView 可见,两个 ListView 不再显示。

编辑:我希望 ListViews 仍然彼此相邻(一个左,另一个右)。

【问题讨论】:

    标签: android xml listview layout textview


    【解决方案1】:

    LinearLayout 的方向更改为垂直

    android:orientation="vertical"
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:baselineAligned="false"
    android:orientation="vertical"
    android:layout_height="match_parent" 
    android:layout_width="match_parent">
    
    
    <TextView 
    android:id="@+id/statusBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Test" />
    
    
    
    <LinearLayout 
    android:orientation="horizontal"
    android:layout_height="match_parent" 
    android:layout_width="match_parent">
    
    <ListView
        android:layout_weight="1" 
        android:id="@+id/rightView" 
        android:layout_height="match_parent" 
        android:layout_width="0dip">
    </ListView>
    
     <ListView
         android:layout_weight="1" 
        android:id="@+id/leftView" 
        android:layout_height="match_parent" 
        android:layout_width="0dip">
    </ListView>
    
    </LinearLayout>
    
    </LinearLayout>
    

    【讨论】:

    • 谢谢。现在显示 ListViews。但一个低于另一个。我想让其中一个在左边,另一个在右边。
    • 谢谢。这样可行。但我收到警告:“嵌套权重不利于性能”。
    • 从 LinearLayout 中移除 weight 属性。
    猜你喜欢
    • 1970-01-01
    • 2012-10-22
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多