|
我的android定制组件有些问题,我想画一个椭圆,但是没反应
这是我在layout xml 文件的代码: <android.project.realtimedata.DemoView android:id="@+id/demoView"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
[/code]
这是我写的定制组件类的代码:
package android.project.realtimedata;
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 DemoView extends View{
ShapeDrawable thisGauge = null;
public DemoView(Context context){
super(context);
init();
}
public DemoView(Context context, AttributeSet attrs)
{
super(context, attrs);
init();
}
private void init(){
int x = 10;
int y = 10;
int width = 300;
int height = 50;
thisGauge = new ShapeDrawable(new OvalShape());
thisGauge.getPaint().setColor(0xff74AC23);
thisGauge.setBounds(x, y, x + width, y + height);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
thisGauge.draw(canvas);
}
}
[/code]
然后在activity的oncreate函数里也有这一行
demoView = (DemoView) findViewById(R.id.demoView);
[/code]
不管我怎么启动程序这组件就是没有,我从logcat里找看到它确实建了,我漏了什么吗?
我来回答 |
|