如何在线性布局中将 TextView 定位在 ListView 上方
How to position a TextView above ListView inside Linear Layout
我试图在线性布局中将 TextView 放置在 ListView 上方,但我很快就无处可去。我已经尝试将电视放置在它自己的布局中,我已经尝试为LV 的顶部,但似乎没有任何效果。电视似乎有某种不可移动的填充物。?请查看屏幕截图和下面的 .XML
设计视图布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/setting_frag"
android:baselineAligned="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"/>
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="?attr/colorBackgroundFloating"
android:descendantFocusability="blocksDescendants" />
<RelativeLayout
android:id="@+id/setting_dialogue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/device_info_stub"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/device_info"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/health_check_stub"
android:inflatedId="@+id/health_check_stub_inflated_id"
android:layout="@layout/health_checks"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/system_config_stub"
android:inflatedId="@+id/system_config_stub_inflated_id"
android:layout="@layout/system_configuration"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/database_stats_stub"
android:inflatedId="@+id/database_stats_stub_inflated_id"
android:layout="@layout/database_stats"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/check_update_stub"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/device_info"
/>
</RelativeLayout>
Screenshot
New screenshot
将android:orientation="horizontal"
更改为android:orientation="vertical"
如您希望您的列表和相关存根并排使用以下代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/setting_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:baselineAligned="false"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F00"
android:textColor="@color/white"
android:text="hello" />
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0F0"
android:descendantFocusability="blocksDescendants" />
</LinearLayout>
<RelativeLayout
android:id="@+id/setting_dialogue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00F"
android:layout_weight="1">
<ViewStub
android:id="@+id/device_info_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
<ViewStub
android:id="@+id/health_check_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/health_check_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
<ViewStub
android:id="@+id/system_config_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/system_config_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
<ViewStub
android:id="@+id/database_stats_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/database_stats_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
<ViewStub
android:id="@+id/check_update_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
</RelativeLayout>
</LinearLayout>
代码的输出将如下所示
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weight_sum ="11"
android:id="@+id/setting_frag"
android:baselineAligned="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="hello"
android:layout_weight="2"/>
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="?attr/colorBackgroundFloating"
android:descendantFocusability="blocksDescendants" />
<RelativeLayout
android:id="@+id/setting_dialogue"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4">
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/device_info_stub"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/device_info"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/health_check_stub"
android:inflatedId="@+id/health_check_stub_inflated_id"
android:layout="@layout/health_checks"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/system_config_stub"
android:inflatedId="@+id/system_config_stub_inflated_id"
android:layout="@layout/system_configuration"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/database_stats_stub"
android:inflatedId="@+id/database_stats_stub_inflated_id"
android:layout="@layout/database_stats"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/check_update_stub"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/device_info"
/>
</RelativeLayout>
我已经做了修改。这对你有用。
我试图在线性布局中将 TextView 放置在 ListView 上方,但我很快就无处可去。我已经尝试将电视放置在它自己的布局中,我已经尝试为LV 的顶部,但似乎没有任何效果。电视似乎有某种不可移动的填充物。?请查看屏幕截图和下面的 .XML
设计视图布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/setting_frag"
android:baselineAligned="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"/>
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="?attr/colorBackgroundFloating"
android:descendantFocusability="blocksDescendants" />
<RelativeLayout
android:id="@+id/setting_dialogue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/device_info_stub"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/device_info"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/health_check_stub"
android:inflatedId="@+id/health_check_stub_inflated_id"
android:layout="@layout/health_checks"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/system_config_stub"
android:inflatedId="@+id/system_config_stub_inflated_id"
android:layout="@layout/system_configuration"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/database_stats_stub"
android:inflatedId="@+id/database_stats_stub_inflated_id"
android:layout="@layout/database_stats"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/check_update_stub"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/device_info"
/>
</RelativeLayout>
Screenshot
New screenshot
将android:orientation="horizontal"
更改为android:orientation="vertical"
如您希望您的列表和相关存根并排使用以下代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/setting_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:baselineAligned="false"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F00"
android:textColor="@color/white"
android:text="hello" />
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0F0"
android:descendantFocusability="blocksDescendants" />
</LinearLayout>
<RelativeLayout
android:id="@+id/setting_dialogue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00F"
android:layout_weight="1">
<ViewStub
android:id="@+id/device_info_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
<ViewStub
android:id="@+id/health_check_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/health_check_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
<ViewStub
android:id="@+id/system_config_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/system_config_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
<ViewStub
android:id="@+id/database_stats_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/database_stats_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
<ViewStub
android:id="@+id/check_update_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/activity_burst_assignees" />
</RelativeLayout>
</LinearLayout>
代码的输出将如下所示
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weight_sum ="11"
android:id="@+id/setting_frag"
android:baselineAligned="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="hello"
android:layout_weight="2"/>
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="?attr/colorBackgroundFloating"
android:descendantFocusability="blocksDescendants" />
<RelativeLayout
android:id="@+id/setting_dialogue"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4">
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/device_info_stub"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/device_info"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/health_check_stub"
android:inflatedId="@+id/health_check_stub_inflated_id"
android:layout="@layout/health_checks"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/system_config_stub"
android:inflatedId="@+id/system_config_stub_inflated_id"
android:layout="@layout/system_configuration"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/database_stats_stub"
android:inflatedId="@+id/database_stats_stub_inflated_id"
android:layout="@layout/database_stats"
/>
<ViewStub
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/check_update_stub"
android:inflatedId="@+id/device_info_stub_inflated_id"
android:layout="@layout/device_info"
/>
</RelativeLayout>
我已经做了修改。这对你有用。