我不知道这是不是一个错误,但如果你尝试这个布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dani.constraint.MainActivity">
<TextView
android:text="Lorem ipsum dolor sit amet, duo aperiri eruditi cu, lorem assum pro eu. Eos ea nostrum detraxit, ne etiam iisque pro. Melius ceteros eu vel, per aliquip habemus at. Vix wisi utinam regione eu. At qui ipsum choro, et primis periculis eos. Putant aperiam mea ad, id mei prompta denique, velit voluptatibus sit ea. Discere accusam an quo."
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textView"
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
android:layout_marginStart="16dp"
app:layout_constraintTop_toTopOf="@+id/activity_main"
android:layout_marginTop="16dp"
app:layout_constraintRight_toRightOf="@+id/activity_main"
android:layout_marginEnd="16dp" />
</android.support.constraint.ConstraintLayout>
文字显示不正确。我认为预期的行为将是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dani.constraint.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Lorem ipsum dolor sit amet, duo aperiri eruditi cu, lorem assum pro eu. Eos ea nostrum detraxit, ne etiam iisque pro. Melius ceteros eu vel, per aliquip habemus at. Vix wisi utinam regione eu. At qui ipsum choro, et primis periculis eos. Putant aperiam mea ad, id mei prompta denique, velit voluptatibus sit ea. Discere accusam an quo." />
</RelativeLayout>
有没有办法在不设置父级填充的情况下获得与relativelayout相同的结果?我正在使用com.android.support.constraint:constraint-layout:1.0.0-alpha4
答案 0 :(得分:1)
这是一个错误,并在alpha 5中修复 - 你需要更新到更新版本的ConstraintLayout(alpha 6刚刚发布)
com.android.support.constraint:约束的布局:1.0.0-alpha6