I am trying to create a custom view:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:id="@+id/container_fl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateTint="#FFFFFF" />
</FrameLayout>
</layout>
And Java:
public class ImageSlideshowView extends FrameLayout {
private ViewImageSlideshowBinding binding;
public ImageSlideshowView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public ImageSlideshowView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
public ImageSlideshowView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
private void init(@NonNull Context context) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
binding = ViewImageSlideshowBinding.inflate(layoutInflater, this, true);
}
}
This works, but not right.
If I use a tag mergeinstead of FrameLayout without data binding, I will get the following layout (I finally want to get this layout):
- FrameLayout
--- ProgressBar
But I can’t use mergewith data binding, so using the XML above I get the following layout:
- FrameLayout
--- FrameLayout
---- ProgressBar
As you can see, another FrameLayout is being created. How to avoid this?
source
share