这是我的xml布局:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="clickHandler"
type="com.myproject.android.customer.ui.adapter.MyHandler" />
<variable
name="item"
type="com.myproject.android.customer.api.model.Merchant" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageViewPhoto"
android:layout_width="@dimen/preview_image_height"
android:layout_height="@dimen/preview_image_height"
android:onClick="clickHandler.onClickImageViewFavorite()"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
</layout>
行。它工作正常。 问题:
像这样痴迷:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable name="test_variable" type="Integer"/>
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageViewPhoto"
android:layout_width="@{test_variable}"
android:layout_height="@dimen/preview_image_height"/>
</android.support.constraint.ConstraintLayout>
</layout>
答案 0 :(得分:0)
您也不必担心,您也可以设置height
元素的width
和Activity
,如下所示
textView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));