簡體   English   中英

在底部 android 中設置適當的約束

[英]set proper constraint in bottom android

嘿,我正在 android 中進行約束布局。 我正在嘗試將我的文本視圖和圖像視圖放在同一行中,並且我的圖像尺寸更大。

在此處輸入圖像描述 .

問題是我想給出適當的約束。 設置適當的約束后,它將如下所示。

在此處輸入圖像描述

活動.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="10dp"
    android:paddingTop="12dp"
    tools:ignore="RtlSymmetry">

    <TextView
        android:id="@+id/testName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/description"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="blah blah blah" />

    <TextView
        android:id="@+id/description"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:layout_marginEnd="5dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/testIcon"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/testName"
        tools:text="blah blah blah blah blah blah blah blah blah blah blah blah" />

    <ImageView
        android:id="@+id/testIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image_pills"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/description"
        app:layout_constraintTop_toBottomOf="@+id/testName"
        tools:ignore="ContentDescription" />

</androidx.constraintlayout.widget.ConstraintLayout>

有人可以指導我如何設置適當的約束。

在第一個 textview 中,您需要進行以下更改:

android:layout_height="0dp"
app:layout_constraintEnd_toStartOf="@+id/testIcon"

在第二個 textview 中,您需要進行以下更改:

android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@+id/testIcon"

在 imageview 中,您需要刪除此行:

app:layout_constraintStart_toEndOf="@+id/description"
app:layout_constraintTop_toBottomOf="@+id/testName"

這是我的示例工作代碼:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/dimen_12"
xmlns:app="http://schemas.android.com/apk/res-auto">

<TextView
    android:id="@+id/textView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toStartOf="@id/imageview"
    app:layout_constraintBottom_toTopOf="@id/textView1"
    android:text="blah blah blah"/>

<TextView
    android:id="@+id/textView1"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintTop_toBottomOf="@id/textView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toStartOf="@id/imageview"
    app:layout_constraintBottom_toBottomOf="@id/imageview"
    android:text="blah blah blah blah blah blah blah blah blah blah blah blah"/>

<ImageView
    android:id="@+id/imageview"
    android:layout_width="100dp"
    android:layout_height="100dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM