У меня есть следующий макет для Android, который отображает списки просмотров списка на экране один в левой стороне, другой на правую сторону.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/ListView01"/>
<ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="3" android:id="@+id/ListView02"/>
Теперь я хочу добавить кнопку, отображающую ее в нижней правой части экрана. Может ли кто-нибудь помочь мне о том, как я могу это сделать?
сначала удалите линейную компоновку, используйте относительную компоновку. Для кнопки используйте следующую команду
android: layout_alignParentBottom = "true" и android: layout_alignParentRight = "true"
Возможное решение: Добавить RelativeLayout в качестве корневого макета и поместить кнопку после LinearLayout со свойствами layout_below и layout_right (LinearLayout как ссылка).
Попробуйте использовать следующий код
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#ffffff"
>
<Button
android:id="@+id/click"
android:layout_width="100dip"
android:layout_height="60dip"
android:text="Click"
android:layout_alignParentRight="true"
/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ListView02"
android:background="#00ff00"
android:layout_toLeftOf="@+id/click"
/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ListView01"
android:background="#000000"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/ListView02"
/>
</RelativeLayout>
Спасибо Дипак