I want to create a custom view that extends LinearLayout
and has children, but also uses a custom layout:
res/layout/control_accordion.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="header"
type="java.lang.String" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:background="?android:background"
android:onClick="@{v -> presenter.setExpanded(!presenter.expanded)}"
android:orientation="horizontal">
<TextView
style="@style/Widget.EditText.FullWidth"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:clickable="false"
android:focusable="false"
android:text="@{ header }" />
<ImageView
android:id="@+id/control_recurrence_expander"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end|center_vertical"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_arrow_drop_down"/>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:divider="?android:dividerHorizontal"
android:orientation="vertical"
android:showDividers="beginning|middle"
android:id="@+id/control_accordion_content">
</LinearLayout>
</LinearLayout>
</layout>
I want to then be able to use this control inside of other layouts and give it children, like this:
<com.myapplication.Accordion>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test 2" />
</com.myapplication.Accordion>
And I would like to have the TextView
s appear inside of control_accordion_content
. How would I accomplish this?