include 要素の layout 属性と同様に、カスタム ビューの子レイアウトを XML で指定したいと思います。
<include layout="@layout/all_apps_cling"
android:id="@+id/all_apps_cling"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
さらに、Eclipse または IntelliJ グラフィカル レイアウト プレビューでデザイン時にレンダリングするカスタム ビューが必要です。
attr name="android:layout" の使用が機能しない
[少なくともグラフィック レイアウトのプレビューではありません]
attrs.xml
<declare-styleable name="ShowcaseView">
<attr name="android:layout"/>
</declare-styleable>
ユースケース.xml
<com.github.espiandev.showcaseview.ShowcaseView
style="@style/ShowcaseView"/>
スタイル.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();
}
解決策はありますか?
<attr name="linkedLayout" format="reference"/>
また、グラフィカル レイアウト プレビューで動作させる必要があるため、使用できません-グラフィック レイアウト ADT プレビューのデザイナー Resources$NotFoundException でリソースにアクセスする問題を参照してください (ただし、アプリは実際には動作します)。