Android layout 有没有办法在图像视图的下角放置浮动操作按钮?
我正在尝试创建一个布局,我希望在右下角的图像按钮的顶部有一个浮动操作按钮。我目前正在使用约束布局。有办法做到这一点吗 编辑: 以下是我当前的实现:Android layout 有没有办法在图像视图的下角放置浮动操作按钮?,android-layout,Android Layout,我正在尝试创建一个布局,我希望在右下角的图像按钮的顶部有一个浮动操作按钮。我目前正在使用约束布局。有办法做到这一点吗 编辑: 以下是我当前的实现: <ImageButton android:id="@+id/option1_button" android:layout_width="match_parent" android:layout_height="0dp"
<ImageButton
android:id="@+id/option1_button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:baselineAlignBottom="true"
android:cropToPadding="false"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/icon1" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/option1_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/option1_button"
app:layout_constraintEnd_toEndOf="@+id/option1_button"
app:layout_constraintStart_toEndOf="@+id/option1_button"
app:layout_constraintTop_toTopOf="@+id/option1_button"
android:src="@drawable/gallery"
app:fabSize="mini"/>
如果您只需将浮动按钮限制在图像视图的顶部(限制顶部和底部),并对水平包含(它们应位于视图的右侧)执行相同操作,就可以实现这一点
根据评论编辑:
<?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">
<ImageButton
android:id="@+id/option1_button"
android:layout_width="0dp"
android:layout_height="642dp"
android:cropToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/option1_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/gallery"
app:fabSize="mini"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline3" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
如果您只需将浮动按钮限制在图像视图的顶部(限制顶部和底部),并对水平包含(它们应位于视图的右侧)执行相同操作,就可以实现这一点
根据评论编辑:
<?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">
<ImageButton
android:id="@+id/option1_button"
android:layout_width="0dp"
android:layout_height="642dp"
android:cropToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/option1_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/gallery"
app:fabSize="mini"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline3" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
谢谢你的回答!当我做出这些改变时,这并没有改变任何事情。将我当前的实现添加到问题中。我做错什么了吗?你现在能检查我更新的答案吗?我删除了一些属性,告诉我它现在是否工作。我将这两个元素嵌套在水平线性布局中的垂直线性布局中。指南应该放在哪里?指南应该放在哪里?把它放在你想放的任何地方,在我的示例中,它的屏幕高度为50%,但这只是一个示例-如果你想更改它,请随意。应用程序在执行此操作后崩溃:(谢谢你的回答!当我做出这些更改时,这并没有真正改变任何事情。将我当前的实现添加到问题中。我是否做错了什么事?你现在可以检查我更新的答案吗?我删除了一些属性,告诉我它现在是否工作。我将这两个元素嵌套在水平线性布局中的垂直线性布局中。)t、 指南应该放在哪里?指南应该放在哪里?放在你想放的任何地方,在我的示例中,它的屏幕高度为50%,但这只是一个示例-如果你想随意更改它。应用程序在实施此操作后崩溃:(