【发布时间】:2012-10-16 17:45:21
【问题描述】:
我正在尝试为小部件创建方形布局。
我有以下布局类:
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: Binary XML file line #2: Error inflating class com.trollhammaren.SquareLayout
如果我将布局更改为 LinearLayout,我会看到一个正常的 LinearLayout,但它不是方形的。
我做错了什么?
【问题讨论】:
-
我没有发现任何明显的错误,您是否尝试过清理您的项目?
-
请发布日志猫的其余部分,它可能包含更多线索,但正如 Sam 所说,它看起来不错。
-
尝试将 SquareLayout 从 com.trollhammaren 移动到 com.trollhammaren.wakeonlandroid。
-
我将 SquareLayout 移至 com.trollhammaren.wakeonlandroid,但没有帮助。之后我将布局更改为 LinearLayout,完全删除应用程序并重新安装它,但它导致投石机崩溃。然后我再次将其更改为 com.trollhammaren.wakeonlandroid.SquareLayout ,但随后它不再出现。重置手机后,小部件再次出现,但我仍然遇到与最初完全相同的错误。该错误是我在 logcat 中看到的唯一消息,直到屏幕自动关闭。
-
我把我的项目添加到了github github.com/Trollhammaren/wakeonlandroid
标签: android android-layout android-widget