我正在开发应用程序,对于它的设计,我需要在两个Reelative布局上方重叠ImageButton或将其设置为哪种布局。
这是我实现的设计
这是我实现的设计的xml
<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:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity">
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="229dp"
android:layout_above="@+id/relative_middle"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="1dp"
android:background="@drawable/layout_back"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</RelativeLayout>
<RelativeLayout
android:id="@+id/relative_middle"
android:layout_width="match_parent"
android:layout_height="323dp"
android:layout_above="@+id/relativeLayout_base"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="0dp"
android:background="@drawable/layout_back_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relativeLayout"
app:layout_constraintVertical_bias="0.0"
tools:ignore="MissingConstraints">
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="117dp"
android:layout_above="@+id/linearLayout2"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
android:layout_marginBottom="-19dp"
android:clipToPadding="false"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="@+id/linearLayout2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/linearLayout2"
app:layout_constraintTop_toBottomOf="@+id/linearLayout2">
<androidx.cardview.widget.CardView
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_margin="10dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@drawable/circleshape"
android:padding="10dp"
android:src="@drawable/settings" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Add"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_margin="10dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground">
// there are some codes here.
</androidx.cardview.widget.CardView>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout_base"
android:layout_width="match_parent"
android:layout_height="113dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="3dp"
android:background="@drawable/layout_back"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.888"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relative_middle"
app:layout_constraintVertical_bias="0.962">
</RelativeLayout>
现在此设计显示了一些问题,例如,相对布局不适合每个屏幕尺寸。
我正在使用dpi可绘制对象来为所有设备实现此设计
我的问题是
1。如何实现在两个相对布局上方重叠的ImageButton?
2。如何实现适合所有设备的设计?
谢谢
[您可以使用FloatingButtons或每当要在其他视图上显示某个视图时,都将两个视图放到内部FrameLayout
FrameLayout
最后的视图将排在其他视图之上。更多细节https://developer.android.com/reference/android/widget/FrameLayout