I want to create a wrapper element that can be reusable throughout the whole app, because it's the base of each screen. This wrapper should be possible to add to layout editor in Android Studio and needs to be able to hold any inner elements inserted in editor. But these elements have to be inserted inside the layout under header with image and only inside a specified area defined in wrapper xml layout (innerContainer).
This is the layout of wrapper:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
...
android:background="@drawable/frame_container_layout"
tools:context=...>
<include
android:id="@+id/cv_header"
layout="@layout/cv_header"
...>
</include>
<android.support.constraint.ConstraintLayout
android:id="@+id/innerContainer"
.../>
</android.support.constraint.ConstraintLayout>
What I need is to use this layout in custom view in a way, that when it's used somewhere, the elements will be only inserted into innerContainer.
Child XML:
<...custom_views.WrapperFragmentView
...
app:exampleColor="#33b5e5"
app:exampleDimension="24sp"
app:exampleDrawable="@android:drawable/ic_menu_add"
app:exampleString="Hello, WrapperFragmentView">
<TextView
android:id="@+id/textView1"
...
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</...custom_views.WrapperFragmentView>
The child is now inserted over the wrapper layout, which is what I don't want. It's not inside innerContainer.
In kotlin file I defined
class WrapperFragmentView : android.support.constraint.ConstraintLayout {
...
private fun init(attrs: AttributeSet?, defStyle: Int) {
var inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
inflater.inflate(R.layout.cv_wrapper_fragment, this, true)
findViewById<android.support.constraint.ConstraintLayout>(R.id.innerContainer)
The innerContainer is the view I want to have as a root element for the children that are going to use it. Not the whole layout cv_wrapper_fragment.
How to set this in the WrapperFragmentView?
Or, if the whole concept is wrong and if there is an easier approach how to work with reusable wrapping elements I am all for that.