布局未从合并标记中获取属性

时间:2018-11-02 13:10:39

标签: android android-layout android-xml custom-view

我有下一个布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_round_rect_4_melanzane_dark"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:paddingStart="16dp"
    android:paddingTop="8dp"
    android:paddingEnd="16dp"
    android:paddingBottom="8dp">
        <TextView />
        <TextView />
        <EditText />
</RelativeLayout>

我在自定义视图中将其夸大,例如:

class LabeledEditText : RelativeLayout {

    constructor(context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)

    init {
        inflate(context, R.layout.view_labeled_edit_text, this)
    }
}

一切正常。但是,如果我更改RelativeLayout以在xml中合并标签,则我的视图将无法获得诸如background和focusable之类的属性。这就是我要更改的方式:

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_round_rect_4_melanzane_dark"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:paddingStart="16dp"
    android:paddingTop="8dp"
    android:paddingEnd="16dp"
    android:paddingBottom="8dp"
    tools:parentTag="android.widget.RelativeLayout">
        <TextView />
        <TextView />
        <EditText />
</merge>

在自定义视图中如何将参数从合并标签转换为父布局?

1 个答案:

答案 0 :(得分:0)

布局不会从合并标记中获取属性。