横幅底部Android

时间:2012-09-20 07:00:07

标签: android relativelayout

如何在屏幕底部设置横幅?
我尝试使用RelativeLayout并保持在底部,但屏幕外。

这是我的简单代码:

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

更新

我设置了android:layout_alignParentBottom =“true”但未更改

4 个答案:

答案 0 :(得分: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>

答案 1 :(得分:1)

将横幅放在RelativeLayout内并使用android:layout_alignParentBottom="true"
检查解决方案:https://stackoverflow.com/a/5380447/1434631

答案 2 :(得分:1)

这是因为身份LinearLayout的{​​{1}}已占据整个屏幕。因此,身份layout_body的{​​{1}}无处可去,但在屏幕底部之外。

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

  1. RelativeLayout更改为layout_banner
  2. RelativeLayoutLinearLayout的{​​{1}}更改为layout_body
  3. layout_banner添加到layout_height
  4. 这应该存档您的要求。

答案 3 :(得分: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>
相关问题