2011-07-11 173 views
0

我想让导航栏位于屏幕的底部。 在最右边会有'上一个'按钮,在左边是'下一个'按钮。 和中心的textview。Android布局问题?

我试过线性和相对布局,但失败了。 当我把宽度=“fill_parent”文本,然后左键消失。

在这里,一个我想:

<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" 
       /> 
     <Button android:id="@+id/nextbtn" 
       android:background="@drawable/next" 
       android:onClick="nextPage" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
</LinearLayout> 
</RelativeLayout> 

回答

2

下面的代码的变化将工作:

  1. 对于TextView的变化 'FILL_PARENT' 到“WRAP_CONTENT两者的高度和宽度。

  2. 对于按钮和textview添加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> 

+0

非常感谢,我接近成功。唯一的问题是背景图像比原始图像更宽,失去图像比例和质量。将试图解决它,但如果你知道答案请帮助,再次感谢。 – javanes

+0

我解决了它。作为按钮的0重量值,textview的1个重量值。 – javanes

0

尝试在两个按钮alignParentLeft="true"alignParentRight="true"

<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> 
+0

我试过,但对不起。所有漂浮到左。那么我这次给中间的一个留下一个消失。 – javanes