在约束布局Android中创建自定义布局

时间:2017-09-27 19:25:55

标签: android android-constraintlayout

如何根据图像中显示的布局在约束布局中进行自定义布局 enter image description here

2 个答案:

答案 0 :(得分:0)

左父+右父母的图标

在左到右图标+右父母

的EditText

使用右重力按钮INSIDE EditText

EditText中的自定义背景

答案 1 :(得分:0)

尝试这样的事情

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:id="@+id/iconImage"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginTop="8dp"
        android:layout_marginLeft="8dp"
        android:src="@mipmap/ic_launcher_round"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintLeft_toRightOf="@id/iconImage"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintRight_toLeftOf="@id/imageBtn"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:hint="I want to..." />

    <ImageButton
        android:id="@+id/imageBtn"
        android:layout_width="48dp"
        android:layout_height="48dp"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintRight_toRightOf="parent"/>

</android.support.constraint.ConstraintLayout>