gpt4 book ai didi

android - SetWidht match_parent的一半

转载 作者:行者123 更新时间:2023-11-29 17:39:14 26 4
gpt4 key购买 nike

我需要相对布局始终具有match_parent宽度的一半,我该怎么做?

<RelativeLayout
android:id="@+id/new_post_nsfw_button"
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_alignRight="@+id/new_post_image"
android:layout_alignBottom="@+id/new_post_image"
android:layout_marginBottom="12dp"
android:layout_marginRight="12dp">
</RelativeLayout>

最佳答案

您可以将这两个RelativeLayouts放置在水平方向的LinearLayout内,然后对两个RelativeLayouts使用权重。这会将LinearLayout分为2个相等的部分。

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
</LinearLayout>

关于android - SetWidht match_parent的一半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29350477/

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