【发布时间】:2017-04-17 03:22:09
【问题描述】:
我有例如约束布局中的 Textview,我希望它与文本一样小(包装内容):
这是我的 XML:
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="This is an example Message."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview1"
android:background="@android:color/holo_green_light"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="16dp"/>
</android.support.constraint.ConstraintLayout>
但我想定义到屏幕右边缘的最小距离。因此,如果文本变大,它目前看起来像这样:
但我希望它看起来像这样:
我该怎么做?
编辑:
我还是没有头绪。 一个已删除的答案建议尝试设置 android:layout_marginRight 和 android:layout_marginEnd
我尝试使用填充,但没有成功。
【问题讨论】:
-
你在用这个版本吗
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha6'如果不是那么试试吧?? -
我应该用它做什么?我还没有办法
-
你想把它放在中间吗?还是在左侧?您希望它覆盖多大的屏幕宽度?
-
如果文本足够短(第一张图片),我希望它保持在左侧并具有文本的大小。否则我希望它不要填满整个屏幕(所以不是图 2)并且在右侧有一点空间(图 3)。请看附图,希望我的担忧能得到解决。
标签: android android-layout user-interface android-xml android-constraintlayout