关于layout_weight的困惑

sno_guo sno_guo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
大家好, android的 linearlayout布局中有一个layout_weight 的选项, 用来分配每个控件占用的比例的, 但我发现一个问题:

我linearlayout中如果只放 Button, TextView这些控件的时候, 是可以按照比例来分配的, 但如果放 ListView 或中间再嵌套一个linearlayout的话, 就好像不起作用了, 请问下为什么, 谢谢.

一下是我嵌套的举例,大家可以测试下.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">

</ListView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
...全文

相关推荐

apktool layout_weight Base64

NULL 博文链接:https://breaklayer.iteye.com/blog/741165

weixin_38669628

奇葩属性:layout_weight 的解释及使用

在Android的控件布局中,有一个奇葩的 layout_weight 属性,定义如下: layout_weight : 用于指定剩余空闲空间的分割比例。用法: <LinearLayout android:orientation="horizontal"> <TextView android:layout_width="wrap_content" an

xjbclz

Android layout_weight使用方法及实例

直接上代码和图片。 情况一:[html] 代码如下:&lt;?xml version=”1.0″ encoding=”utf-8″?&gt; <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”horizontal”>     &lt;fragment         android:id=”@+id/tit

weixin_38691482

Android应用中通过Layout_weight属性用ListView实现表格

今天主要说的是对Layout_weight属性的完全解析,以及利用Layout_weight这个属性使用ListView来实现表格的效果,我们都知道Android里面专门有一个TableLayout来实现表格的,说实话,我平常开发中用TableLayout还是比较少的,几乎没有用到,我们完全可以用LinearLayout和RelativeLayout来代替TableLayout的使用,自己开发中主要使用LinearLayout,RelativeLayout这两种布局,不过刚开始我还是偏爱于RelativeLayout,因为在RelativeLayout里面我们可以直接拖拽控件来布局,比较方便,

weixin_38591291

Android中的android:layout_weight使用详解

layout_weight的作用是设置子空间在LinearLayout的重要度(控件的大小比重)。layout_weight的值越低,则控件越重要,下面为大家介绍下具体的使用方法

weixin_38537689
评论 7
收藏 已收藏
分享
返回顶部
sno_guo
Android 80,490 成员 91,371 内容