Android XML中的形状可绘制视图

Android XML中的形状可绘制视图,android,xml,view,Android,Xml,View,我正在逐字(几乎)使用ShapedRavable示例,似乎无法在xml中调用ShapedRavable类。文档中所述的唯一额外步骤是覆盖视图(Context,AttributeSet),我想我是这样做的。我指的文档在这里:这是我的代码 AndroidTest.java package com.android.test; import android.app.Activity; import android.os.Bundle; public class AndroidTest extends

我正在逐字(几乎)使用ShapedRavable示例,似乎无法在xml中调用ShapedRavable类。文档中所述的唯一额外步骤是覆盖视图(Context,AttributeSet),我想我是这样做的。我指的文档在这里:这是我的代码

AndroidTest.java

package com.android.test;

import android.app.Activity;
import android.os.Bundle;

public class AndroidTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
}
}
ShapeSquare.java

package com.android.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.util.AttributeSet;
import android.view.View;

public class ShapeSquare extends View {
private ShapeDrawable mDrawable;

public ShapeSquare(Context context, AttributeSet attrs) {
    super(context, attrs);

    int x = 10;
    int y = 10;
    int width = 300;
    int height = 50;

    mDrawable = new ShapeDrawable(new OvalShape());
    mDrawable.getPaint().setColor(0xff74AC23);
    mDrawable.setBounds(x, y, x + width, y + height);
}

protected void onDraw(Canvas canvas) {
    mDrawable.draw(canvas);
}
}
main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<com.android.test.shapedrawable.ShapeSquare
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
/>

</LinearLayout>


这个错误是一个强制退出错误,我不知道问题出在哪里。形状属性将由用户输入决定(最终),因此形状需要在类中创建,而不是在所有xml中创建。

解决了这里的问题。我必须从以下内容中删除“ShapedRavable”:



显然,那只是演示的位置。我以为它不知怎么引用了这个类。

解决了这个问题。我必须从以下内容中删除“ShapedRavable”:



显然,那只是演示的位置。我以为它不知怎么引用了这个类。

plz显示你的logcat输出..plz显示你的logcat输出。。
<com.android.test.shapedrawable.ShapeSquare
android:layout_width="fill_parent" 
android:layout_height="wrap_content"  
/>