你可以使用这个来实现ConstraintLayout.这是一个模板:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello world"
android:maxLines="1"
android:ellipsize="end"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintWidth_default="wrap"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/button"
app:layout_constraintBottom_toBottomOf="parent"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELLO WORLD"
app:layout_constraintLeft_toRightOf="@+id/text"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBaseline_toBaselineOf="@+id/text"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
初始设置是:
魔术带有TextView宽度和app:layout_constraintWidth_default属性.通过将宽度设置为0dp并将"默认宽度"设置为包装,我们告诉Android为视图提供尽可能多的空间,只要它符合约束即可保存其内容.当文本非常长时,约束将使其不会按下屏幕右侧的按钮.
| 归档时间: |
|
| 查看次数: |
52 次 |
| 最近记录: |