Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 解决数据绑定不支持合并标记的问题_Android_Android Databinding - Fatal编程技术网

Android 解决数据绑定不支持合并标记的问题

Android 解决数据绑定不支持合并标记的问题,android,android-databinding,Android,Android Databinding,我有一个自定义视图组,它扩展了LinearLayour,使用标记扩展XML布局文件,并引用此布局文件中的视图 CustomViewGroup.java public class CustomViewGroup extends LinearLayout { public CustomViewGroup(final Context context, @Nullable final AttributeSet attrs) { super(context, attrs);

我有一个自定义视图组,它扩展了
LinearLayour
,使用
标记扩展XML布局文件,并引用此布局文件中的视图

CustomViewGroup.java

public class CustomViewGroup extends LinearLayout {
    public CustomViewGroup(final Context context, @Nullable final AttributeSet attrs) {
        super(context, attrs);

        inflate(context, R.layout.view_custom, this);

        this.<TextView>findViewById(R.id.first).setText("Hello");
        this.<TextView>findViewById(R.id.second).setText("World");
    }
}
此解决方案有一个缺点-现在视图层次更深,因为有一个冗余的
FrameLayout


有没有一种方法可以使用数据绑定库,它具有
标记的所有优点,即不加深视图层次结构?

您所说的合并是什么意思???@AngusTay我的意思是这里描述的
标记:@pskink如果我将
替换为
,我将在
CustomViewGroup
内部膨胀
CustomViewGroup
太糟糕了,安卓团队两年后仍然没有对其进行开发。你觉得这个有用吗?:)
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:id="@+id/first"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/second"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</merge>
public class CustomViewGroup extends LinearLayout {
    public CustomViewGroup(final Context context, @Nullable final AttributeSet attrs) {
        super(context, attrs);

        final ViewCustomBinding binding = ViewCustomBinding.inflate(LayoutInflater.from(context), this, true);

        binding.first.setText("Hello");
        binding.second.setText("World");
    }
}


<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/first"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/second"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
</layout>