layout - Android的布局剩余高度的问题
黄舟
黄舟 2017-04-17 11:00:45
[Android讨论组]

在apkbus上看到的一个问题,之前也遇到过,后来便不了了之。

下面是该问题当时的答案,总觉的有些不太优美。大家有什么好方法么?谢谢。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffe0e8ec"
    android:orientation="vertical" >
    
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="20dip" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1.0" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="20dip" />

</LinearLayout>

附原地址:
http://www.apkbus.com/android-43921-1...

---------------------------------更新-------------------------------------

由于我对android:layout_weight属性的不了解导致了这个问题的出现,经过研究发现android:layout_weight是个很有趣的属性,上面的解决方法非常巧妙。

先来看看什么是android:layout_weight:

Layout weight is used to determine how Android pides up any left over space after the various widgets get all of the space they want.

上面代码中将中间LinearLayout的android:layout_weight设置为1,也就等于中间的LinearLayout占据了剩下的所有空间,很好了解决的layout中高度的问题。

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(3)
迷茫

思路1:用RelativeLayout布局
思路2:设置LinearLayout的android:layout_gravity
暂时想到这两个方法,不过目前没在开发环境下,明天试试看是否可行 : )

天蓬老师

使用layout_weight

PHPz

对的,用权重的话是很容易解决大部分问题的,而且对于不同分辨率的适应性还是比较不错的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号