文本在约束布局android中被剪切掉

Rak*_*hna 5 android android-layout android-constraintlayout

我使用以下布局来实现在约束布局的右端带有图像的视图,在图像的左侧带有文本:

<LinearLayout
 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:orientation="vertical" 
         android:layout_width="match_parent"
         android:layout_height="match_parent">

  <android.support.constraint.ConstraintLayout             
    android:id="@+id/parentPanel"             
    android:layout_width="wrap_content"             
    android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/image"
                 android:layout_width="64dp"
                 android:layout_height="64dp"
                 app:layout_constraintRight_toRightOf="parent"
                 android:background="#ff0000"/>

            <TextView
                android:id="@+id/txt"
                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Lorem Ipsum is simply dummy text of the printing
 and typesetting industry. Lorem Ipsum has been the industry's
 standard dummy text ever since the 1500s, when an unknown printer took
 a galley of type and scrambled it to make a type specimen book"
                 app:layout_constraintTop_toTopOf="parent"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintRight_toLeftOf="@+id/image"
                 android:textColor="#000000"
                 android:textSize="20sp"/>
         </android.support.

constraint.ConstraintLayout>
     </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我已附上了从XML上面获得的UI的屏幕截图。文本过长时,文本将从左侧截断。

屏幕截图_1

屏幕截图_2

在build.gradle中使用的依赖项是:

编译'com.android.support.constraint:constraint-layout:1.0.1'

Meh*_*ria 0

你必须更改LinearLayoutConstraintLayout. 您的布局应如下所示。

<?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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/parentPanel"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" >

        <ImageView
            android:id="@+id/image"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:background="#ff0000"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"  />

        <TextView
            android:id="@+id/txt"
            android:layout_width="0dp"
            android:layout_height="120dp"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:text="Lorem Ipsum is simply dummy text of the printing
 and typesetting industry. Lorem Ipsum has been the industry's
 standard dummy text ever since the 1500s, when an unknown printer took
 a galley of type and scrambled it to make a type specimen book"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:textColor="#000000"
            android:textSize="20sp"
            app:layout_constraintVertical_bias="0.0"
            app:layout_constraintRight_toLeftOf="@+id/image"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="8dp" />
    </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

输出:

  • 你不应该在另一个约束布局中使用约束布局 (3认同)
  • 约束布局被开发为具有平面布局设计。平面布局在运行时比层次布局具有更好的性能。您可以删除第一个约束布局 (3认同)