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

问题描述 投票:0回答:1

我有下一个布局:

<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中合并标记,我的视图不会获得诸如背景和可聚焦的属性。这就是我改变它的方式:

<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>

我必须做些什么才能在我的自定义视图中从合并标签到父布局获取参数?

android android-layout android-xml custom-view
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.