首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >layout_weight=".4“看起来比layout_weight=".6”大

layout_weight=".4“看起来比layout_weight=".6”大
EN

Stack Overflow用户
提问于 2017-01-17 12:14:09
回答 4查看 131关注 0票数 2

这。我不明白为什么第一个布局看起来比第二个布局更大,如果最后一个布局有.6 (60%)。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".4" >

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".6">
    </RelativeLayout>
</LinearLayout>
EN

回答 4

Stack Overflow用户

发布于 2017-01-17 12:18:43

@Miguel Barra适用于此

代码语言:javascript
复制
   android:layout_width="match_parent"

替换为

代码语言:javascript
复制
   android:layout_width="wrap_content"

代码语言:javascript
复制
   android:layout_width="0dp"

在这两个相对布局中

票数 1
EN

Stack Overflow用户

发布于 2017-01-17 12:19:17

老实说,我没有尝试过分数权重值,但理论上它们应该是有效的。但我认为这里的问题是,您需要将这两个相对布局的layout_width设置为0dp。只有这样,权重参数才会生效。试试看。来自android文档-

要创建每个子级使用相同屏幕空间的线性布局,请将每个视图的android:layout_height设置为"0dp“(对于垂直布局)或将每个视图的android:layout_width设置为"0dp”(对于水平布局)。然后将每个视图的android:layout_weight设置为“1”。

票数 0
EN

Stack Overflow用户

发布于 2017-01-17 12:21:01

你应该拿着这个。

如果使用权重,则有两种情况

情况1:如果你有水平的父级。你应该有layout_width="0dp“

代码语言:javascript
复制
 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight=".6" >

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight=".4">
        </RelativeLayout>
    </LinearLayout>

案例1:如果你有垂直的父级。你应该有layout_height="0dp“

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".6" >

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".4">
    </RelativeLayout>
</LinearLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41688963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档