我创造了一个
CardView
小部件,其中
TextView
是。的文本
文本视图
运行时中的更改。我怎么能绑住我的
卡地维
宽度到
文本视图
宽度?
到目前为止我所做的:
在
卡地维
,我补充说,
android:layout_alignLeft="@id/textViewUser"
但它不能作为
文本视图
不能使用此方法嵌套。有什么想法吗?
一小段
卡地维
项目如下。请注意,我删除了限制,使它更短。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/cardViewUser"
android:layout_width="300dp"
android:layout_height="30dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
card_view:cardCornerRadius="4dp"
card_view:elevation="14dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="I change during runtime"
android:id="@+id/textViewUser"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>