Android 顶部线性布局在底部线性布局之前占用最大空间

Android 顶部线性布局在底部线性布局之前占用最大空间,android,layout,android-linearlayout,android-relativelayout,Android,Layout,Android Linearlayout,Android Relativelayout,首先,这里是我的activity_main.xml文件的结构: 相对论 线性布局 片段(谷歌地图) 线性布局 西格巴 文本视图 图像按钮 我试图将第二个线性布局(不包含地图的布局)粘贴到底部,而地图占据了屏幕上的其余空间(在该布局之前停止)。我目前拥有的解决方案在我的GS3上运行良好,但第二个LinearLayout没有在较小屏幕设备上显示(可能是因为我的第一个LinearLayout的定义大小(480dp)) 我怎样才能做到这一点 这是我的xml文件: <?xml ver

首先,这里是我的activity_main.xml文件的结构:

  • 相对论
    • 线性布局
      • 片段(谷歌地图)
    • 线性布局
      • 西格巴
      • 文本视图
      • 图像按钮
我试图将第二个线性布局(不包含地图的布局)粘贴到底部,而地图占据了屏幕上的其余空间(在该布局之前停止)。我目前拥有的解决方案在我的GS3上运行良好,但第二个LinearLayout没有在较小屏幕设备上显示(可能是因为我的第一个LinearLayout的定义大小(480dp))

我怎样才能做到这一点

这是我的xml文件:

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

    <LinearLayout
        android:id="@+id/map_layout"
        android:layout_width="match_parent"
        android:layout_height="480dp"
        android:orientation="vertical">

        <fragment
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal" />
    </LinearLayout>

    <LinearLayout
        android:layout_below="@+id/map_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <SeekBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/price_seekbar" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="1€"
            android:progress="3"
            android:max="15"
            android:id="@+id/price_seekbar_value" />

        <ImageButton
            android:id="@+id/advanced_search_image_button"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="right"
            android:src="@drawable/advanced_search_icon" />

    </LinearLayout>

</RelativeLayout>


谢谢你的建议

您可以在片段下将第二个布局包含到第一个布局中,并设置第一个布局的布局\u height=“match\u parent”。这样,它将在每个屏幕大小上工作。使用静态值来定义高度不是件好事。。。在两个布局上设置相同的id是不好的!;)让我知道这对您是否是一个好的解决方案!:)

在第一个
线性布局中
使用

android:layout_above="@+id/second_linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
在第二个
线性布局中
使用

android:layout_alignParentBottom="true"

我认为它将解决您的问题

用LinearLayout替换RelativeLayout,并使用
android:gravity=“bottom”
。 对于第一个线性布局(带贴图),请将属性设置为:

android:layout_height="0dip"
android:layout_weight="0.4"

另一种方法-对于第二个布局,使用android:layout\u alignParentBottom=“true”
,并将id更改为不同的内容(例如“映射按钮”)

首次布局使用

android:layout_above="@id/map_buttons"
android:layout_height="match_parent"

将以下内容替换为您的XML

对于第一个
线性布局
,请替换此

<LinearLayout
    android:id="@+id/map_layout"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/rest_of_layout"
    android:orientation="vertical" >
<LinearLayout
    android:id="@+id/rest_of_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal" >

我就这么做了。谢谢,这正是我想要的:)