android - ConstraintLayout中如何用两个view填满屏幕?

标签 android android-constraintlayout

我试图在屏幕顶部放置一个 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>

结果: enter image description here

关于android - ConstraintLayout中如何用两个view填满屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45815284/

相关文章:

android - 如何在父级为 ScrollView 的约束布局中将元素逐个放置在另一个元素下面

android - ConstraintLayout 和 RelativeLayout 的区别

android - 具有两个链式 TextView 的约束布局无法正确呈现

android - 如何在 Sencha Touch 2 中制作签名的 APK

android - RecyclerView textChangeListener 或数据绑定(bind)

java - 如何控制对话框背景触摸?

java - Android Studio 约束布局改变绝对

android - 如何使 GridLayoutManager 中的某个项目的高度相对于另一个项目进行调整?

Android - 谷歌地图清除缓存

java - 自定义注解Java/android