如何在Android中实现以下垂直布局?
View1
View2
View3
Run Code Online (Sandbox Code Playgroud)
所有三个视图都具有适合屏幕的宽度.
View2
高度是固定的(= 100).
View1
高度等于view3's
高度.
我能够有实现这一目标LinearLayout
,RelativeLayout
,ConstraintLayout
?
如果有一个程序化的解决方案,而不是XML
布局,我会很感激.
试试这个 LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@color/colorAccent"/>
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/colorDarkBlue"/>
<View
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
OUTPUT
归档时间: |
|
查看次数: |
54 次 |
最近记录: |