0

我正在创建一个应用程序,当我触摸人类时,它会显示不同的部件名称。在此处输入图像描述

我的主要活动课程如下......

  public class VideosActivity extends Activity implements OnTouchListener {
        //DrawView draw;
        float a=0;
        float b=0;
        ImageView image;
        MotionEvent event;
        Button  back ;
        Button next;
        TextView t;
        String info = "";
        int count =0;
        FirstImage i;
        ViewFlipper c;
        Infoview v;
        String huma="human";
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
             setContentView(R.layout.videos_layout);
             i=new FirstImage(this);
             v=new Infoview(this);
             c=(ViewFlipper) findViewById(R.id.viewFlipper1);
             back = (Button) findViewById(R.id.button1);
             next = (Button) findViewById(R.id.button2);
             t=(TextView) findViewById(R.id.textView1);
             if(count==0)
                i.changeImage(R.drawable.human ); 
             i.invalidate();
             c.addView(i,0);
             c.setOnTouchListener(this);
                c.onTouchEvent(event);
             addListenerOnButton();


    }

 public void pageinfo(float a,float b){

        t.setText(Float.toString(a)+"x"+Float.toString(b)+"y");
        if(i.getSrc()==R.drawable.human){
            v.updateInfo(huma, a, b);
            i.invalidate();
            v.invalidate();
        }
    }



    public boolean onTouch(View v, MotionEvent me) {
        // TODO Auto-generated method stub
        switch(me.getAction()){
        case MotionEvent.ACTION_DOWN:
            a=me.getX();
            b= me.getY();
            pageinfo(a,b);
            break;
        case MotionEvent.ACTION_MOVE:
            a=me.getX();
            b= me.getY();
            pageinfo(a,b);
            break;
        case MotionEvent.ACTION_UP:
            a=me.getX();
            b= me.getY();
            pageinfo(a,b);
            break;
        case MotionEvent.ACTION_OUTSIDE:
            a=me.getX();
            b= me.getY();
            pageinfo(a,b);
            break;
        default: return false;
        }
        return true;

    }
    }

用于在图像上显示文本的另一个类 infoView 无法正常工作.....

public class Infoview extends View {

 String info = "";
 float x = 0; //init value 
 float y = 0; //init value
 int color = Color.WHITE;

 public Infoview(Context context) {
  super(context);
  // TODO Auto-generated constructor stub
 }

 public Infoview(Context context, AttributeSet attrs) {
  super(context, attrs);
  // TODO Auto-generated constructor stub
 }

 public Infoview(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);

  Paint paint = new Paint();
  paint.setStyle(Paint.Style.FILL_AND_STROKE);
  paint.setColor(color);
  paint.setStrokeWidth(2);
  paint.setTextSize(30);

  canvas.drawLine(x-10, y, x+10, y, paint);
  canvas.drawLine(x, y-10, x, y+10, paint);
  canvas.drawText(info, x, y, paint);

 }

 public void updateInfo(String t_info, float t_x, float t_y){
  info = t_info;
  x = t_x;
  y = t_y;
  invalidate();
 }

 public void clearInfo(){
  info = "";
  x = 0;
  y = 0;
  invalidate();
 }

}

它没有显示任何输出....

4

0 回答 0