您的位置:首页 > 其它

用RelativeLayout实现上下控件高度不变,中间的控件高度随着屏幕高度变化,适应整个屏幕

2016-11-30 20:39 1726 查看
今天做一个界面做了很久

,又是获取屏幕高度,控件高度效果都不理想,先说说我想做什么吧!

整个布局分为上中下,上面LinearLayout写了一些基本信息,中间是一个RelativeLayout.,下面是用LinearLayout嵌套一个GridView,我是想中间的高度可以根据上下布局的变化而变化,从而能够恰好布满整个屏幕,开始我是获取上下布局的高度和屏幕的高度相减得到中间的高度,这样做也是可以的,但是就是加载的时候反应较慢,效果看起来很不理想,也可能是我方法不对吧。然后发现其实布局就能搞定

,因为费心好久,所以写一个博客记住,免得下次又来。。。


上布局:

<?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"
android:background="@color/content_bg">

<LinearLayout
android:id="@+id/userInfo_view"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:paddingBottom="10dp">
</LinearLayout>

<RelativeLayout
android:id="@+id/mapView_rl"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_above="@+id/gridview_ll"
android:layout_below="@id/userInfo_view">

<RelativeLayout
</RelativeLayout>

<LinearLayout
android:id="@+id/gridview_ll"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:paddingTop="8dp">

<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:horizontalSpacing="2dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp" />
</LinearLayout>
</RelativeLayout>

gridview是固定的几个模块,高度没什么大的变化,然后就是这样啦。。

ok,说到这里,就算完了,希望能对大家有点用处

,拜~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐