我想创建一个扩展LinearLayout
并拥有子项的自定义视图,但也使用自定义布局:
RES /布局/ 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>
我希望能够在其他布局中使用此控件并为其提供子项,如下所示:
<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>
我希望TextView
出现在control_accordion_content
内。我该如何做到这一点?