[英]Top LinearLayout to take maximum space before bottom LinearLayout
首先,这是我的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>
感谢您的意见。
将以下内容替换为您的XML ...
对于第一个LinearLayout
,请替换为...
<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
,替换此...
<LinearLayout
android:id="@+id/rest_of_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
您可以在片段下将第二个布局包含在第一个布局中,并设置第一个布局的layout_height =“ match_parent”。 这样,它将适用于所有屏幕尺寸。 使用静态值定义高度不是一件好事...并且在两个布局上设置相同的id也不是一件好事! ;)让我知道这是否对您来说是一个很好的解决方案! :)
在第一个LinearLayout
使用
android:layout_above="@+id/second_linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
在第二个LinearLayout
使用
android:layout_alignParentBottom="true"
我认为它将解决您的问题
用LinearLayout替换RelativeLayout并使用android:gravity="bottom"
。 对于第一个LinearLayout(带有Maps),请将属性设置为此:
android:layout_height="0dip"
android:layout_weight="0.4"
另一种方法-对于第二个布局,请使用android:layout_alignParentBottom="true"
,并将id更改为其他名称(例如,“ map_buttons”)
第一次布局使用
android:layout_above="@id/map_buttons"
android:layout_height="match_parent"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.