如何实现以下布局 - 中间的一个固定高度视图和顶部和底部的两个相等高度视图?

use*_*898 1 layout android

如何在Android中实现以下垂直布局?

View1
View2
View3
Run Code Online (Sandbox Code Playgroud)

所有三个视图都具有适合屏幕的宽度.

View2高度是固定的(= 100).
View1高度等于view3's高度.

我能够有实现这一目标LinearLayout,RelativeLayout,ConstraintLayout

如果有一个程序化的解决方案,而不是XML布局,我会很感激.

Gok*_*oku 5

试试这个 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 次

最近记录:

7 年,9 月 前