【发布时间】:2021-08-01 07:18:30
【问题描述】:
我希望测试视图只占用卡片其余部分所占据的高度。 (见代码sn-p末尾的图片)但它正在将视图的高度推到整个屏幕。
只有在提供 0 高度后才能正常工作,这似乎不正确。 除了提供 0 高度 来实现这种行为,还能做什么?
<RelativeLayout 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:gravity="center"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
<TextView
android:id="@+id/dialog_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:layout_marginEnd="8dp"
android:background="@android:color/holo_red_light"
android:text="Dialog title"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<View
android:id="@+id/test"
app:layout_constraintTop_toTopOf="parent"
android:background="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="5dp"
android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>```
what I want [1]: https://i.stack.imgur.com/8NU4d.png
what shows up [2]: https://i.stack.imgur.com/K6qEn.png
【问题讨论】:
-
分享您想要设计的布局。
-
@MehulKabaria 我想要什么 [1]:i.stack.imgur.com/8NU4d.png 出现了什么 [2]:i.stack.imgur.com/K6qEn.png
-
我已经发布答案检查它
-
@MehulKabaria,感谢您的回答,r 可以在没有 0 dp 的情况下做到这一点,?在我的问题中也提到过同样的事情
-
我能知道没有 0dp 的原因是什么吗??
标签: android-view android-constraintlayout viewgroup android-wrap-content