横幅底部Android

问题描述:

如何在屏幕底部设置横幅?
我试着用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请参阅我的答案,如果答案对您有帮助,请接受。 –

在底部使用下面的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> 

把你的旗帜RelativeLayout内使用android:layout_alignParentBottom="true"
检查解决方案:https://*.com/a/5380447/1434631

如果你想保持你的观点线性布局,您可以添加它与属性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> 

这是因为编号为layout_bodyLinearLayout已占据整个屏幕。所以RelativeLayout与编号layout_banner没有去哪里,但在屏幕的底部之外。

相反,你可以尝试以下方法:

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

这应该存档你的需求换货。