に基づいた次のカスタム ビューがありますRelativeLayout
。
public class LearningModeRadioButton extends
RelativeLayout
implements
Checkable,
View.OnClickListener {
private void init(Context context, AttributeSet attrs) {
LayoutInflater.from(context).inflate(R.layout.rb_learning_mode, this, true);
}
}
R.layout.rb_learning_mode
内容は次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RadioButton
android:id="@+id/rb"
android:button="@drawable/sel_rb_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/tv_mode_title"
style="@style/text_regular"
android:layout_toRightOf="@+id/rb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/tv_description"
style="@style/text_small"
android:layout_below="@+id/tv_mode_title"
android:layout_alignLeft="@+id/tv_mode_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</merge>
ある程度は機能しますが、レイアウト パラメーター ( layout_xxx
) は無視されます。レイアウトのルート要素として別のものを使用することもできます<RelativeLayout/>
が、ビュー階層に余分なレベルを持たないようにしたいと考えています。
問題は、内部でレイアウト属性を機能させるにはどうすればよいかということ<merge/>
です。