1
내 XML 레이아웃 :java 파일에서 변수의 값을 설정할 수 있습니까? 여기
<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>
확인을 클릭합니다. 괜찮아. 질문 :
- 은 자바 파일에서 XML의 변수 test_variable의 값을 설정할 수 있습니까?
- 이 변수의 값을 android : layout_width으로 설정 하시겠습니까?
같이 Somithing :
<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>
다음과 같이
Activity
에서height
및 요소의width
을 설정할 수 있습니다 또한 당신을 걱정할 필요가 없습니다 ** 높이 ** XML 파일에만 **. 나는 이것을 위해 자바 코드를 사용하지 않을 것이다. – Alex