【发布时间】:2017-04-05 20:54:59
【问题描述】:
我在一个 udacity android 教程中看到,这可以通过使用 ImageView 和 TextView 来实现,其中 TextView wrt 到 ImageView 指定了约束。但是这是在没有硬编码框的尺寸(即宽度和高度)的情况下实现的。 ImageView 分别设置为 0dp,ImageView 仅使用约束进行扩展。)
我尝试了以下,但没有给出正确的结果:
<ImageView
android:id="@+id/imageViewTable"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="parent"
android:layout_marginTop="10dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"/>
<TextView
android:id="@+id/textViewTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
app:layout_constraintLeft_toLeftOf="@id/imageViewTable"
app:layout_constraintRight_toRightOf="@id/imageViewTable"
app:layout_constraintTop_toTopOf="@id/imageViewTable"
app:layout_constraintBottom_toBottomOf="@id/imageViewTable"
/>
我知道有一种使用 padding 的简单方法,但我想知道如何以这种方式完成(使用 0dp imageview)
【问题讨论】:
-
你为什么不做一个带有填充和绿色背景的文本视图?
-
@Tiago 我知道可以这样做。但我想知道使用 0dp ImageView 的“技巧”。我已编辑问题以反映这一点。
标签: android android-layout view android-constraintlayout