您正在混合
LinearLayout
用一个
ConstraintLayout
. 虽然这是允许的,但您可以使用
ConstraintLayout约束
这将简化您的布局。这是一个模型:
我添加了背景色以显示小部件的范围。您似乎也从样式中获得了宽度和高度属性;我已经把它们说清楚了。
我利用了
match_constraints
(
0dp
在布局中)这是
ConstraintLayout约束
.
Here
是关于小部件约束的官方文档,有助于解释发生了什么。
以下是上图的XML:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_light"
android:text="Currently playing Currently playing Currently playing Currently playing Currently playing Currently playing Currently playing Currently playing Currently playing Currently playing Currently playing Currently playing "
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/current_artist"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:background="@android:color/holo_blue_light"
android:text="Current artist Current artist Current artist Current artist Current artist Current artist Current artist Current artist Current artist Current artist Current artist Current artist Current artist "
app:layout_constraintEnd_toStartOf="@+id/current_radio"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/current_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:background="@android:color/holo_green_light"
android:text="Current title Current title Current title Current title Current title Current title Current title Current title Current title Current title Current title Current title Current title "
app:layout_constraintEnd_toStartOf="@+id/current_radio"
app:layout_constraintStart_toStartOf="@+id/current_artist"
app:layout_constraintTop_toBottomOf="@+id/current_artist"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/current_radio"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="16dp"
android:background="@android:color/holo_orange_dark"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher_foreground"
app:layout_constraintBottom_toBottomOf="@+id/current_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/current_artist"
tools:ignore="ContentDescription" />
</android.support.constraint.ConstraintLayout>