这是我的活动
public class HelloAndroIDActivity extends Activity{ /** Called when the activity is first created. */ @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentVIEw(R.layout.main); CustomImageVIEw myVIEw = new CustomImageVIEw(getApplicationContext()); System.out.println("Setting the vIEw"); myVIEw.invalIDate(); setContentVIEw(myVIEw); System.out.println("Calling invalIDate"); }}
这是我的CustomImageVIEw
public class CustomImageVIEw extends ImageVIEw{ /** * @param context */ public CustomImageVIEw(Context context) { super(context); // Todo auto-generated constructor stub setBackgroundcolor(0xFFFFFF); } /** * @param context * @param attrs */ public CustomImageVIEw(Context context,AttributeSet attrs) { super(context,attrs); // Todo auto-generated constructor stub } /** * @param context * @param attrs * @param defStyle */ public CustomImageVIEw(Context context,AttributeSet attrs,int defStyle) { super(context,attrs,defStyle); // Todo auto-generated constructor stub } @OverrIDe protected voID onDraw(Canvas canvas) { // Todo auto-generated method stub super.onDraw(canvas); System.out.println("Painting content"); Paint paint = new Paint(Paint.liNEAR_TEXT_FLAG); paint.setcolor(0x0); paint.setTextSize(12.0F); System.out.println("Drawing text"); canvas.drawText("Hello World in custom vIEw",100,paint); } @OverrIDe public boolean ontouchEvent(MotionEvent event) { // Todo auto-generated method stub Log.d("Hello AndroID","Got a touch event: " + event.getAction()); return super.ontouchEvent(event); }}
即使打印ontouchEvent()中的日志消息,也没有打印任何内容.
这是我的main.xml的布局
<?xml version="1.0" enCoding="utf-8"?><absoluteLayout androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/absoluteLayout"></absoluteLayout>解决方法 使用颜色值color.WHITE或color.BLACK而不是六进制值. 总结
以上是内存溢出为你收集整理的android – 创建自定义ImageView全部内容,希望文章能够帮你解决android – 创建自定义ImageView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)