ウィジェットの正方形のレイアウトを作成しようとしています。
次のレイアウトクラスがあります。
package com.trollhammaren;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.LinearLayout;
public class SquareLayout extends LinearLayout {
// constructors
public SquareLayout(Context context) {
super(context);
}
public SquareLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
// methods
@Override
protected void onMeasure(int width, int height) {
Log.v("widget", "resized");
super.onMeasure(width, height);
}
}
そして、次のxml:
<?xml version="1.0" encoding="utf-8"?>
<com.trollhammaren.SquareLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dip"
android:background="@drawable/myshape" >
</com.trollhammaren.SquareLayout>
正方形の代わりに、「ウィジェットの読み込みに問題があります」というテキストを含む長方形のウィジェットが表示されます。ウィジェットを配置すると、logcat に次のメッセージが表示されます。
AppWidget の膨張エラー AppWidgetProviderInfo(provider=ComponentInfo{com.trollhammaren.wakeonlandroid/com.trollhammaren.wakeonlandroid.WidgetProvider}): android.view.InflateException: バイナリ XML ファイル行 #2: クラス com.trollhammaren.SquareLayout の膨張エラー
レイアウトを LinearLayout に変更すると、通常の LinearLayout が表示されますが、正方形ではありません。
私は何を間違っていますか?