代码之家  ›  专栏  ›  技术社区  ›  Kalpesh Lakhani

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

  •  -4
  • Kalpesh Lakhani  · 技术社区  · 7 年前

    全部的

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

    附笔 为了澄清困惑,我的整个屏幕应该是这样的 actual screen

    提前谢谢。 请回答。

    3 回复  |  直到 6 年前
        1
  •  2
  •   AskNilesh    7 年前

    您可以使用 RelativeLayout enter image description here

    试试这个

    <?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>
    
        2
  •  2
  •   ND1010_    7 年前

    试试这个

    输出:

    enter image description here

       <?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"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context="com.nct.dhruv.demotest.LogCatActivity">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@color/colorPrimary" />
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@color/colorAccent" />
    
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/linear"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal"
            android:layout_centerVertical="true"
            android:layout_alignParentStart="true">
    
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_marginRight="10dp"
                android:orientation="vertical"
                android:layout_height="wrap_content">
    
                <android.support.design.widget.FloatingActionButton
                    android:id="@+id/floatingActionButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher"
                    app:backgroundTint="#fff" />
    
            </LinearLayout>
    
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_height="wrap_content">
    
                <android.support.design.widget.FloatingActionButton
                    android:layout_width="wrap_content"
                    app:backgroundTint="#fff"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher" />
    
            </LinearLayout>
    
        </LinearLayout>
    
    
    </RelativeLayout>
    
        3
  •  1
  •   Firoz Memon SANCHIT SRIVASTAVA    7 年前

    如果你喜欢使用 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>
    

    它输出:

    Image Using ConstraintLayout

    注: 你的 UpperLayer LowerLayer 可以是任何 Layout View ,未固定到 LinearLayout