Reputation: 6659
I would like to specify a child layout for a custom view in XML, analogously to the layout attribute of the 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, I need the custom view to render at design-time in Eclipse or IntelliJ graphical layout preview
[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);
// Get the attributes for the ShowcaseView
final TypedArray styled = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ShowcaseView, 0, 0);
TypedValue handLayout = null;
// Not sure if should be using .getValue in the first place
// But there is no method TypedValue.getLayout or such
if (styled.getValue(R.styleable.ShowcaseView_android_layout, handLayout)) {
// Does not reach here
} else {
// Reaches here instead i.e. getValue failed
}
styled.recycle();
}
And I cannot use <attr name="linkedLayout" format="reference"/>
, because I need it to work in the graphical layout preview - see the problem of accessing resources in the designer Resources$NotFoundException in Graphical Layout ADT preview (but app actually Works)
Upvotes: 1
Views: 1282
Reputation: 24720
try to place your layout in master layout file:
<ShowcaseView ...>
<include .../>
</ShowcaseView>
of course you can also add children directly instead of include tag:
<ShowcaseView ...>
<Button .../>
...
<Button .../>
</ShowcaseView>
Upvotes: 2