gpt4 book ai didi

java - Android Studio - 权重总和

转载 作者:行者123 更新时间:2023-12-02 04:22:55 25 4
gpt4 key购买 nike

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:layout_weight="2">

<TextView
android:id="@+id/centerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#FFFFFF"
android:textSize="28sp"
android:text="HALLO ALLE"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/centerText"
android:layout_centerHorizontal="true"/>

</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:layout_weight="8"
android:orientation="horizontal">


<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Btn 1"
android:layout_weight="2"/>
</LinearLayout>

大家好,这是我的代码,我对此有疑问我在第一个 LinearLayout 中设置了 weightSum 我设置了 weightSum 10,其中 RelativeLayout 有 2/10,另一个 (LinearLayout) 有 8/10,正如我在 IDE (Android Studio) 的预览中看到的那样, RelativeLayout 是更大的,这是我的问题:

值较小的layout_weight会是较大的吗?

最佳答案

不,layout_weight 的值应该越大。使用 layout_weight 时,您应该将高度或宽度设置为 0dp;在垂直布局中,您处理的是高度,而在水平布局中,您处理的是宽度。

因此,在您的情况下,您的根布局是垂直的 LinearLayout。其中,权重为“2”的相对布局应具有 android:layout_height="0dp",权重为“8”的 LinearLayout 也应具有相同的布局。

关于java - Android Studio - 权重总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32544782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com