安卓底部工具栏布局

5
这是我的安卓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>

请查看此链接:https://dev59.com/dloV5IYBdhLWcg3wnf7r#42119958 - Fartab
4个回答

10

使用 android:layout_alignParentBottom="true" 将 linearlayout 设置在父布局底部,使用 android:layout_above 将 mapview 设置在 linearlayout 上方。

你的代码应该是这样的:

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

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

0

使用RelativeLayout的属性,例如android:layout_alignParentBottomandroid: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>

-2
尝试以下布局。仅使用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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接