friend 们,我试图将 view1 的高度设置为填充文本 textView1 的高度,但它不起作用。 view1 因此无限长,超过了文本的高度,占据了整个屏幕,但我需要文本的末尾。
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/cv">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:background="@android:color/white">
<View
android:id="@+id/view1"
android:background="@drawable/rectangle_with_color"
android:layout_height="wrap_content"
android:layout_width="16dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="3dp"
android:text="Не следует, однако забывать, что начало повседневной работы по формированию позиции представляет собой интересный эксперимент проверки новых предложений. С другой стороны реализация намеченных плановых заданий представляет собой интересный эксперимент проверки форм развития."
android:gravity="top"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
矩形_with_color.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#E41300" />
</shape>
最佳答案
修复了您的错误。请使用下面的代码:
<View
android:id="@+id/view1"
android:background="@drawable/blank_checkbox"
android:layout_height="wrap_content"
android:layout_width="16dp"
android:layout_alignBottom="@+id/textView1"/> //make this change
You need to set alignBottom property to mark its end.
根据文档:
alignBottom: Makes the bottom edge of this view match the bottom edge of the given anchor view ID. Accommodates bottom margin.
关于java - wrap_content 或 match_parent 未给出正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61275244/