i have open question on here trying solve, , might have found possible solution less error-prone; however, don't know how code solution.
the solution similar how android.support.design.widget.navigationview handles header view in xml!! problem have tried search source code navigationview, cannot seem find it. can find other android source code - except newer design library.
if can find source code google, can implement similar.
code
<android.support.design.widget.navigationview android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:menu="@menu/drawer" app:headerlayout="@layout/drawer_header" /> see last line? want able own customview insert view inside it.
so question is:
where source code design library's navigationview?
or
is there custom view allows insert layouts inside of has code posted online?
or
if there nothing online, how person go doing that? possible. navigationview it.
here exmaple how might it:
in resources.xml:
<declare-styleable name="mycustomview"> <attr name="child_view" format="reference" /> </declare-styleable> in mycustomview.java:
public class mycustomview extends viewgroup { public mycustomview(context context, attributeset attrs) { super(context, attrs); typedarray = context.gettheme().obtainstyledattributes(attrs, r.styleable.mycustomview, 0, 0); int childview = a.getresourceid(r.styleable.mycustomview_child_view, r.layout.default_child_view); a.recycle(); layoutinflater.from(context).inflate(childview, this, true); } } in layout file:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <your.package.mycustomview android:layout_width="match_parent" android:layout_height="wrap_content" custom_view:child_view="@layout/some_layout" /> </linearlayout>
Comments
Post a Comment