android - pass in a layout resource using custom attributes for a custom view -


i specify child layout custom view in xml, analogously layout attribute of include element:

<include layout="@layout/all_apps_cling"          android:id="@+id/all_apps_cling"          android:layout_width="match_parent"          android:layout_height="match_parent"/> 

furthermore, need custom view render @ design-time in eclipse or intellij graphical layout preview

using attr name="android:layout" not work

[at least not in graphical layout preview]

attrs.xml

<declare-styleable name="showcaseview">     <attr name="android:layout"/> </declare-styleable> 

usecase.xml

<com.github.espiandev.showcaseview.showcaseview     style="@style/showcaseview"/> 

styles.xml

<style name="showcaseview" parent="match_fill">     <item name="android:layout">@layout/handy</item> </style> 

showcaseview.java

public showcaseview(context context) {     this(context, null, r.styleable.customtheme_showcaseviewstyle); }  public showcaseview(context context, attributeset attrs) {     this(context, attrs, r.styleable.customtheme_showcaseviewstyle); }  public showcaseview(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle);     // attributes showcaseview     final typedarray styled = context.gettheme().obtainstyledattributes(attrs, r.styleable.showcaseview, 0, 0);     typedvalue handlayout = null;     // not sure if should using .getvalue in first place     // there no method typedvalue.getlayout or such      if (styled.getvalue(r.styleable.showcaseview_android_layout, handlayout)) {         // not reach here     } else {         // reaches here instead i.e. getvalue failed     }     styled.recycle(); } 

any solutions?

and cannot use <attr name="linkedlayout" format="reference"/>, because need work in graphical layout preview - see problem of accessing resources in designer resources$notfoundexception in graphical layout adt preview (but app works)

try place layout in master layout file:

<showcaseview ...>     <include .../> </showcaseview>  

of course can add children directly instead of include tag:

<showcaseview ...>     <button .../>     ...     <button .../> </showcaseview>  

Comments