我试图在屏幕顶部放置一个 Button,在其下方放置一个需要填满屏幕(所有屏幕尺寸)的 ImageView。 在 RelativeLayout 中似乎很容易做到,但是在 ConstraintLayout 中我没有成功。
Here is an example of what it's look like in RelativeLayout:
和 XML 代码:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Download Image"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:onClick="downloadImage" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView"
android:layout_below="@+id/button"
android:layout_alignParentStart="true" />
感谢您的帮助, 谢伊。
最佳答案
也许我没有完全理解您的问题,但这是我为重新创建您给出的示例图像所做的工作:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView27"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.59"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button2"
app:srcCompat="@drawable/common_google_signin_btn_icon_dark" />
</android.support.constraint.ConstraintLayout>
关于android - ConstraintLayout中如何用两个view填满屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45815284/