Android 实现以下设计(附图)的最佳方法是什么?

Android 实现以下设计(附图)的最佳方法是什么?,android,android-layout,android-xml,Android,Android Layout,Android Xml,全部, 我知道这并不难,但我只想知道哪一个是实现这一目标的最佳途径。您可以在两个布局(黑色和白色)之间看到两个图标。我知道我们可以通过保证金来实现这一点,但还有其他更好的方法吗 p.S为了澄清困惑,我的整个屏幕应该是这样的 提前谢谢。 答案将不胜感激。试试这个 输出: 您可以使用RelativeLayout 试试这个 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://s

全部,

我知道这并不难,但我只想知道哪一个是实现这一目标的最佳途径。您可以在两个布局(黑色和白色)之间看到两个图标。我知道我们可以通过保证金来实现这一点,但还有其他更好的方法吗

p.S为了澄清困惑,我的整个屏幕应该是这样的

提前谢谢。
答案将不胜感激。

试试这个

输出:


您可以使用
RelativeLayout

试试这个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:orientation="vertical">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/nilu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccentJob"
            android:orientation="vertical"
            android:paddingBottom="30dp">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />


        </LinearLayout>

        <LinearLayout
            android:id="@+id/nilu2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/nilu"
            android:background="@color/colorAccentAdhoc"
            android:orientation="vertical"
            android:paddingTop="30dp">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="NILU" />

        </LinearLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/nilu"
            android:layout_marginTop="-15dp"
            android:orientation="horizontal">

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginEnd="16dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_toStartOf="@+id/floatingActionButton"
                android:src="@mipmap/ic_launcher_round"
                app:elevation="2dp" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/floatingActionButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentTop="true"
                android:layout_marginEnd="139dp"
                android:layout_marginRight="30dp"
                android:src="@mipmap/ic_launcher" />

        </RelativeLayout>


    </RelativeLayout>


</RelativeLayout>

如果您想使用
ConstraintLayout
试试:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content">

    <!--UpperLayer-->
    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@android:color/black"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </LinearLayout>

    <!--LowerLayer-->
    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@android:color/darker_gray"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout"
        app:layout_constraintStart_toStartOf="@+id/linearLayout"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout">


    </LinearLayout>

    <!--MiddleLayer-->
    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout2"
        app:layout_constraintStart_toStartOf="@+id/linearLayout2"
        app:layout_constraintTop_toTopOf="@+id/linearLayout2">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:src="@android:drawable/ic_menu_add" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@android:drawable/ic_menu_add" />
    </LinearLayout>


</android.support.constraint.ConstraintLayout>

注意:
您的
上层
下层
可以是任何
布局视图
,而不是固定到
线性布局

使用框架布局:使用
浮动操作按钮
布局锚定
attribute@VishvaDave,Abhishek thanksUse Coordinator layout(类固醇框架布局)Dhruv,如果布局高度不固定,是否可能?在我的例子中,它是包装内容。而且它完全基于内容,所以我甚至不能在此使用权重。同样,在我的例子中,它不是浮动按钮,只是简单的按钮。我尝试了你的代码,但如果我设置它为wrap_content,那么它就不起作用了,如果我使用fix Hightyup,它就可以正常工作,因为线性布局需要一些内部视图,即子视图,正如你在附加图像中看到的那样,它确实有内部布局(请参阅黑白布局中的内部视图)–谢谢你的回答。。如果布局高度不固定,是否可能?就我而言,它是包装的_content@KalpeshLakhani是的,您可以向我的ans查询,如果有任何查询,请告诉我,但我不能使用重量,因为两个容器中的内容都是动态的。还有其他方法吗?在我的情况下,不需要浮动按钮,它只是简单的按钮/图像视图。是的,您可以使用您选择的任何视图@Kalpeshlakhaniks firoz for asnwer,如果布局高度不固定,是否可能?在我的情况下,它是包裹内容是的,您可以根据需要更改
布局高度
。谢谢,让我试试这个:)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content">

    <!--UpperLayer-->
    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@android:color/black"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </LinearLayout>

    <!--LowerLayer-->
    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="0dp"
        android:layout_height="200dp"
        android:background="@android:color/darker_gray"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout"
        app:layout_constraintStart_toStartOf="@+id/linearLayout"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout">


    </LinearLayout>

    <!--MiddleLayer-->
    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout2"
        app:layout_constraintStart_toStartOf="@+id/linearLayout2"
        app:layout_constraintTop_toTopOf="@+id/linearLayout2">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:src="@android:drawable/ic_menu_add" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@android:drawable/ic_menu_add" />
    </LinearLayout>


</android.support.constraint.ConstraintLayout>