Android <;合并/>;在自定义视图xml布局中
我有以下基于Android <;合并/>;在自定义视图xml布局中,android,android-layout,Android,Android Layout,我有以下基于RelativeLayout的自定义视图: public class LearningModeRadioButton extends RelativeLayout implements Checkable,
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\u学习模式
内容包括:
<?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\u xxx
)被忽略了。我可以使用另一个
作为布局的根元素,但我希望避免视图层次结构中有额外的级别
因此问题是:如何使
中的布局属性工作?合并对线性布局和框架布局有用它不适合相对布局
显然,在这种情况下使用是可行的,因为活动内容视图的父级始终是FrameLayout。例如,如果布局使用LinearLayout作为其根标记,则无法应用此技巧。不过,在其他情况下,该方法可能会很有用
对于仍在努力解决此问题的任何人,您应该在合并标记内指定
parentTag
属性。您还需要指定layout\u高度
和layout\u宽度
以使其正常工作
//子视图
编辑现在应该可以正确地显示所有内容。您找到什么了吗?我也有同样的问题。它最终可以工作,但在编辑器中看起来很难看…@Redwarp不,我只是使用了额外的
RelativeLayout
:(