Reputation: 121
I'm attempting to place a TextView above a ListView inside a Linear Layout but I'm getting nowhere fast.. I've tried placing the TV in it's own layout, I've tried adding a margin to the top of the LV, but nothing seems to work.. The TV appears to have some kind of unremovable padding.. ? Please see screenshot and .XML below
Design View layout
<?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>
Upvotes: 3
Views: 195
Reputation: 1857
change android:orientation="horizontal"
to android:orientation="vertical"
As you want your List and relative stub side by side use following code.
<?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>
The output of the code will be like below
Upvotes: 1
Reputation: 3001
<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>
I have made the changes. This will work for you.
Upvotes: 0