我有一个 FrameLayout,上面显示了一个 LinearLayout 我的意图是这个 LinearLayout 总是占据屏幕的 33% ......但我做不到。我尝试使用“dp”,但当然,结果因密度而异。如果它们是两个 LinearLayout,如果我可以使用 layout_weight = ".33" 和 layout_weight = ".67" 但 FrameLayout 在其中一个中使用。
我希望能正确解释
提前致谢
问候
我有一个 FrameLayout,上面显示了一个 LinearLayout 我的意图是这个 LinearLayout 总是占据屏幕的 33% ......但我做不到。我尝试使用“dp”,但当然,结果因密度而异。如果它们是两个 LinearLayout,如果我可以使用 layout_weight = ".33" 和 layout_weight = ".67" 但 FrameLayout 在其中一个中使用。
我希望能正确解释
提前致谢
问候
自 2015 年 8 月以来,您可以使用原生布局PercentFrameLayout和PercentRelativeLayout执行这种布局。从版本 23 开始,两者都可以在 Android 支持库中找到。
你可以尝试这样的事情。第一层是 ImageView,第二层有两个线性布局。
<FrameLayout
android:layoit_height="match_parent"
android:layout_width="match_parent">
<ImageView
android:layoit_height="match_parent"
android:layout_width="match_parent"
android:image="@drawable/screen_image"/> //blue image whith white "screen"
<LinearLayout
android:layoit_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layoit_height="0dp"
android:layout_weight=".67"
android:layout_width="match_parent"
android:background="#00000000"/>
<LinearLayout
android:layoit_height="0dp"
android:layout_weight=".33"
android:layout_width="match_parent"
android:background="#44FF0000"> //33% layout
//children for 33% layout here
</LinearLayout>
</LinearLayout>
</FrameLayout>