[英]Bottom bar layout in android
這是我的android xml源代碼,用於地圖 - 底欄布局。 我在屏幕上顯示一個巨大的地圖,我需要在屏幕底部有一個30dp的高布局,以顯示一些像圖像一樣的標簽。 如何將水平線性布局推到頁面底部?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height=" what here ? "
android:layout_width="fill_parent"
android:orientation="vertical">
<com.google.android.maps.MapView
android:id="@+id/map_view"
Map goes here. Almost full screen. Exactly full - 30dp;
/>
<LinearLayout>
I want 3 images here. Bottom of the screen.
</LinearLayout>
</RelativeLayout>
使用android:layout_alignParentBottom="true"
在linearlayout的父級底部設置linearlayout,為mapview設置android:layout_above
,在maplayout上方設置mapview。
您的代碼將是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout android:layout_height="30dip"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:id="@+id/linearLayout1"
>
<!-- ... -->
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/map_view"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_above="@+id/linearLayout1"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/rel_bottom" />
<RelativeLayout
android:id="@+id/rel_bottom"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_height="30dp" >
<ImageView
android:id="@+id/img1"
android:layout_width="40dp"
android:layout_height="fill_parent" />
<ImageView
android:id="@+id/img2"
android:layout_width="40dp"
android:layout_height="fill_parent"
android:layout_toRightOf="@+id/img1" />
<ImageView
android:id="@+id/img3"
android:layout_width="40dp"
android:layout_height="fill_parent"
android:layout_toRightOf="@+id/img2" />
</RelativeLayout>
</RelativeLayout>
使用RelativeLayout的屬性,如android:layout_alignParentBottom
和android:layout_above
。
我會做這樣的事情:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:id="@+id/footer"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:width="fill_parent"
android:height="30dp">
add your images here
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/map_view"
android:height="fill_parent"
android:width="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="@id/footer"/>
</RelativeLayout>
嘗試以下布局。 使用android:layout_alignParentBottom="true"
是不夠的,因為帶有android:layout_height="fill_parent"
的MapView將填滿整個屏幕並隱藏LinearLayout。 你還必須添加android:layout_above="@id/menu"
這樣它就不會隱藏它。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/menu"
android:apiKey="@string/google_maps_api_key"
android:clickable="true" />
<LinearLayout
android:id="@+id/menu"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true" >
</LinearLayout>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.