2012-09-20 132 views
3

如何在屏幕底部設置橫幅?
我試着用RelativeLayout,它保持底部,但在屏幕外。
橫幅底部Android

這是我簡單的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_home" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background" 
    android:orientation="vertical"> 

     <LinearLayout 
      android:id="@+id/layout_body" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@drawable/background2" 
      android:orientation="vertical"> 

      ...... 
     </LinearLayout> 
     <RelativeLayout 
      android:id="@+id/layout_banner" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 
     .... 
     </RelativeLayout> 
</LinearLayout> 

UPDATE

我已經設置的android:layout_alignParentBottom = 「真」,但不能更改

+0

你是什麼意思的「外屏」? – Shrikant

+0

我想,我們需要設置橫幅的高度和寬度,取決於設備的分辨率。 – 2012-09-20 07:03:48

+0

@enfix請參閱我的答案,如果答案對您有幫助,請接受。 –

回答

2

在底部使用下面的XMl代碼顯示橫幅。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_home" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background"> 

     <LinearLayout 
      android:id="@+id/layout_body" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@drawable/background2" 
      android:orientation="vertical" 
      android:layout_above="@+id/layout_banner"> 

      ...... 
     </LinearLayout> 
     <RelativeLayout 
      android:id="@+id/layout_banner" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true"> 
     .... 
     </RelativeLayout> 
</RelativeLayout> 
0

如果你想保持你的觀點線性佈局,您可以添加它與屬性android:layout_weight="1"像填充間隙空視圖:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_home" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:id="@+id/layout_body" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/login" 
     android:orientation="vertical"> 

     ...... 
    </LinearLayout> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" /> 
    <AnyLayout (you choose) 
     android:id="@+id/layout_banner" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 
    .... 
    </AnyLayout> 
</LinearLayout> 

或者你可以設置一個RelativeLayout的

裏面全
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_home" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background"> 

    <LinearLayout 
     android:id="@+id/layout_body" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/login" 
     android:orientation="vertical"> 

     ...... 
    </LinearLayout> 
    <AnyLayout (you choose) 
     android:id="@+id/layout_banner" 
     android:layout_alignParentBottom="true" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 
    .... 
    </AnyLayout> 
</RelativeLayout> 
1

這是因爲編號爲layout_bodyLinearLayout已佔據整個屏幕。所以RelativeLayout與編號layout_banner沒有去哪裏,但在屏幕的底部之外。

相反,你可以嘗試以下方法:

  1. 更改RelativeLayoutLinearLayout
  2. 變化layout_bodylayout_bannerlayout_heightwarp_content
  3. 添加layout_weight="1"layout_body

這應該存檔你的需求換貨。