[英]FrameLayout with layout_weight is considered useless
考虑以下布局:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
/>
<TextView
android:id="@+id/primary_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@color/white"
android:textSize="24sp"
tools:text="Primary!"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:id="@+id/secondary_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@color/white"
android:textSize="24sp"
tools:text="Secondary!"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
/>
</LinearLayout>
请参阅下面的屏幕截图以了解结果。 布局工作正常,但 Android Studio 警告我FrameLayout
被认为是无用的,应该删除。 然而,它们并非毫无用处。 我在这里使用layout_weight
。 这个想法是两个TextView
之间和周围的空间是相对的,权重为 2:1:3。
如何重写我的布局,从而使视图具有相同的加权定位,而不必使用空的FrameLayout
?
你可以摆脱前两次FrameLayout
你的高度设置TextView
到0dp和他们的体重给你们,请设置的值FrameLayout
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.