I want to have navigation bar at the bottom of my screen. There will be 'Prev' button at rightest and a 'Next' button at leftest. And a textview on center.
I tried linear and relative layout but failed. When I put width="fill_parent" to text then left button dissappears.
Here the one I tried:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/rlayout"
android:layout_height="fill_parent"
>
<!-- other content a listview etc.
-->
<LinearLayout android:id="@+id/navigator"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button android:id="@+id/prevbtn"
android:background="@drawable/prev" android:onClick="prevPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/pageText"
android:text=""
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
开发者_如何学C />
<Button android:id="@+id/nextbtn"
android:background="@drawable/next"
android:onClick="nextPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
The following code changes will work:
For the textview change 'fill_parent' to 'wrap_content for both height and width.
For the buttons and the textview add
android:layout_weight="1"
.
<LinearLayout
android:id="@+id/navigator"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/prevbtn"
android:onClick="prevPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/pageText"
android:text=""
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/nextbtn"
android:onClick="nextPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
Try alignParentLeft="true"
and alignParentRight="true"
on the two buttons.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/rlayout"
android:layout_height="fill_parent"
>
<!-- other content a listview etc.
-->
<LinearLayout android:id="@+id/navigator"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button android:id="@+id/prevbtn"
android:background="@drawable/prev"
android:onClick="prevPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alignParentLeft="true" />
<TextView
android:id="@+id/pageText"
android:text=""
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<Button android:id="@+id/nextbtn"
android:background="@drawable/next"
android:onClick="nextPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alignParentRight="true" />
</LinearLayout>
</RelativeLayout>
精彩评论