有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在材料设计领域创建主/细节

如何将立面添加到主视图/详图视图的详图窗格中,以便在其下方提供阴影,并将其放置在部分覆盖工具栏的位置(如下图所示)?我试着使用安卓:elevation="4dp",但那对我不起作用

XML布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:orientation="vertical">

    <include layout="@layout/toolbar_singleline"/>

    <LinearLayout
        xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"

        安卓:layout_width="match_parent"
        安卓:layout_height="match_parent"
        安卓:baselineAligned="false"
        安卓:divider="@drawable/divider_vertical"
        安卓:orientation="horizontal"
        安卓:showDividers="middle">

        <RelativeLayout
            安卓:id="@+id/master_container"
            安卓:layout_width="0dp"
            安卓:layout_height="match_parent"
            安卓:layout_weight="1"/>

        <FrameLayout
            安卓:id="@+id/detail_container"
            安卓:elevation="4dp"
            安卓:layout_width="0dp"
            安卓:layout_height="match_parent"
            安卓:layout_weight="3"/>
    </LinearLayout>
</LinearLayout>

当前的无聊结果 enter image description here

预期结果 enter image description here

主工具栏下的项目

<RelativeLayout
    安卓:id="@+id/master_container"
    安卓:layout_width="0dp"
    安卓:layout_height="match_parent"
    app:layout_constraintHorizontal_weight="2"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/divider"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/masterToolbar" />

共 (1) 个答案

  1. # 1 楼答案

    这看起来有点复杂,尤其是考虑到搜索操作栏图标与“主”列的最右边对齐

    我怀疑这在功能上是一个FrameLayout(或子类)持有一个水平LinearLayout,其中“细节”窗格作为CardView(具有0dp角半径)覆盖在其余内容上。下面是一个快速模板:

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/masterToolbar"
            android:layout_width="0dp"
            android:layout_height="?actionBarSize"
            android:background="?colorPrimary"
            app:layout_constraintEnd_toStartOf="@+id/detailBackgroundToolbar"
            app:layout_constraintHorizontal_weight="2"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/detailBackgroundToolbar"
            android:layout_width="0dp"
            android:layout_height="?actionBarSize"
            android:background="?colorPrimary"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_weight="3"
            app:layout_constraintStart_toEndOf="@+id/masterToolbar"
            app:layout_constraintTop_toTopOf="parent" />
    
        <View
            android:id="@+id/divider"
            android:layout_width="1dp"
            android:layout_height="0dp"
            android:background="#aaa"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toEndOf="@+id/masterToolbar"
            app:layout_constraintTop_toBottomOf="@+id/masterToolbar" />
    
        <View
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="#eee"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/divider"
            app:layout_constraintTop_toBottomOf="@+id/detailBackgroundToolbar" />
    
        <androidx.cardview.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_margin="4dp"
            app:cardCornerRadius="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/divider"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintWidth_percent="0.3">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
    
                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/detailToolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize"
                    android:background="#ccc"
                    app:title="Detail title" />
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="#fff"
                    android:lineSpacingMultiplier="1.2"
                    android:padding="16dp"
                    android:text="@string/lorem_medium"
                    android:textColor="#1b1b1b"
                    android:textSize="16sp" />
    
            </LinearLayout>
    
        </androidx.cardview.widget.CardView>
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    enter image description here

    <> P>这里唯一真正的窍门是假的“DealIdBealToeToeBar”工具栏,它仅用于正确地定位主工具栏(主工具栏需要在屏幕中间结束,以便动作图标位于正确的位置)。p>