我有两个线性布局,每个都占据了总空间的50%。 里面有不同的意见,我不明白为什么horizontalScrollView1
和listView1
(看ID)不可见。 这两个视图应该扩展以填充其父项中剩余的空间。 我做错了什么?为什么android layout_weight不能按预期工作?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent">
<HorizontalScrollView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<HorizontalScrollView
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:id="@+id/horizontalScrollView1">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"/>
</HorizontalScrollView>
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello!!!" />
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/listView1"/>
</LinearLayout>
</LinearLayout>
您忘记为两个具有权重总和的父线性布局添加方向类型[android:orientation =“vertical”],请检查readyandroid答案以获得更多说明。 –