2013-08-04 144 views
-2

enter image description hereAndroid如何將RelativeLayout對齊到底部?

我可以告訴你在佈局上面的prnt屏幕,我實際上有我的xml和我假裝有的佈局。我在相對佈局設置中做了一些更改,但無法解決它。

下面是代碼:

@佈局/ gridview.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/BackGroundColor" 
    android:orientation="vertical" 
    android:scaleType="center" > 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="2dp" 
     android:layout_marginBottom="0dp" 
     android:layout_marginLeft="0dip" 
     android:layout_marginRight="0dip" 
     android:background="@color/BlueOcean" /> 

    <GridView 
     android:id="@+id/grid" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_margin="4dp" 
     android:columnWidth="100dp" 
     android:horizontalSpacing="5dip" 
     android:listSelector="@layout/gridview_selector" 
     android:numColumns="3" 
     android:padding="1dp" 
     android:scaleType="fitCenter" 
     android:stretchMode="columnWidth" 
     android:verticalSpacing="4dp" /> 

    <RelativeLayout 
     android:id="@+id/overviewBottomBar" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_gravity="bottom" 
     android:gravity="top"  
     android:background="@layout/overviewbottombar_selector" 
     android:textSize="14sp"> 

     <TextView 
      android:id="@+id/overviewScreenLeft" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginLeft="39dp" 
      android:text="Left" 
      android:textColor="@color/holo_blue_dark" /> 

     <View 
      android:id="@+id/overviewBottomBarDividerLeft" 
      android:layout_width="1dp" 
      android:layout_height="32dp" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="39dp" 
      android:layout_toRightOf="@+id/overviewScreenLeft" 
      android:background="@color/darker_gray" /> 

     <TextView 
      android:id="@+id/overviewScreenCenter" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/overviewScreenLeft" 
      android:layout_alignBottom="@+id/overviewScreenLeft" 
      android:layout_centerHorizontal="true" 
      android:text="Center" 
      android:textColor="@color/holo_blue_dark" /> 

     <View 
      android:id="@+id/overviewBottomBarDividerRight" 
      android:layout_width="1dp" 
      android:layout_height="32dp" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="38dp" 
      android:layout_toRightOf="@+id/overviewScreenCenter" 
      android:background="@color/darker_gray" /> 

     <TextView 
      android:id="@+id/overviewScreenRight" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/overviewScreenCenter" 
      android:layout_alignBottom="@+id/overviewScreenCenter" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="39dp" 
      android:text="Right" 
      android:textColor="@color/holo_blue_dark" /> 
    </RelativeLayout> 

</LinearLayout> 

哪些錯誤呢?

感謝

+0

這可能是重複的:http://stackoverflow.com/問題/ 2386866/how-to-align-views-the-the-bottom-of-the-screen看看是否有幫助。 – Qberticus

回答

3

問題不在於RelativeLayout,而在於從上到下佈局子項的LinearLayout。我能想到的最簡單的方法,就是增加與layout_weight間隔查看=「1」在GridView和RelativeLayout的,像這樣之間:

<GridView ... /> 

<!-- spacer view taking up all excess space --> 
<View android:id="@+id/spacer" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    /> 

<RelativeLayout ... /> 
+0

真棒回答!這將在未來幫助我很多。謝謝你 –

-1
<TextView 
     android:id="@+id/overviewScreenLeft" 
     android:layout_alignParentTop="true" 

這是你的問題。你想alignParentBottom="true"

0

讓你的根佈局RelativeLayout,你可以設置android:layout_alignParentBottom="true"RelativeLayout您用ID創建「overviewBottomBar」。然後,它將顯示在底部。