Adding a button in the button right side of the screen
I have the following android layout that displays toe list views in the screen one in left side one t开发者_如何学编程he other to right side.
<?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"/>
Now I want to add a button displayed it the bottom right side of the screen. Can anyone help me about how I could do that?
first remove the linear layout,use relative layout.for button use the following command
android:layout_alignParentBottom="true" and android:layout_alignParentRight="true"
A possible solution should be: Add a RelativeLayout as root layout and put the button after the LinearLayout with properties layout_below and layout_right (LinearLayout as reference).
Try to use the following code
<?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>
Thanks Deepak
精彩评论