gpt4 book ai didi

android - weightSum 不能在 android 中正确分割屏幕

转载 作者:行者123 更新时间:2023-11-29 15:43:42 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:orientation="horizontal"
android:weightSum="2">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:id="@+id/mainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Default Text"
android:textSize="24dip" />


<TextView
android:id="@+id/detailsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:text="Default Text"

android:layout_gravity="center_horizontal" />


</LinearLayout>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="Hot"
/>

</LinearLayout>

我想将屏幕宽度分成两部分。第一部分将有 2 个文本(第二个在第一个下面),第二个拆分部分有一个按钮。

上面的布局将屏幕分成 3 个部分。我不明白为什么?

谁能帮我解决这个问题?我想在第一个文本下方显示第二个文本

最佳答案

试试这个有证据的

    <?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">


<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">

<TextView
android:id="@+id/mainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Default Text"
android:textSize="24dip" />


<TextView
android:id="@+id/detailsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_weight="0.5"
android:text="Default Text" />
</LinearLayout>


<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:text="Hot" />
</LinearLayout>


</RelativeLayout>

enter image description here

关于android - weightSum 不能在 android 中正确分割屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36400885/

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