横幅底部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 = “真”,但不能更改
答
在底部使用下面的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://stackoverflow.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_body
的LinearLayout
已占据整个屏幕。所以RelativeLayout
与编号layout_banner
没有去哪里,但在屏幕的底部之外。
相反,你可以尝试以下方法:
- 更改
RelativeLayout
到LinearLayout
- 变化
layout_body
和layout_banner
的layout_height
到warp_content
- 添加
layout_weight="1"
到layout_body
这应该存档你的需求换货。
你是什么意思的“外屏”? – Shrikant
我想,我们需要设置横幅的高度和宽度,取决于设备的分辨率。 – 2012-09-20 07:03:48
@enfix请参阅我的答案,如果答案对您有帮助,请接受。 –