如果我将一项活动更改为另一项活动,任何机构都可以告诉我如何安排图像。我的代码是
public class Small extends Activity {
// Instance variables
private Paint mPaint,mBitmapPaint;
private MyView mView;
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
public View onDraw;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.small);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
imageview = (ImageView)findViewById(R.id.image);
imageview1 = (ImageView)findViewById(R.id.ic_launcer);
forword = (ImageButton)findViewById(R.id.forword);
back = (ImageButton)findViewById(R.id.back);
relativelayout = (RelativeLayout)findViewById(R.id.item);
//select_color = (ImageButton) findViewById(R.id.color);
DisplayMetrics metrics = getBaseContext().getResources().getDisplayMetrics();
int w = metrics.widthPixels;
int h = metrics.heightPixels;
System.out.println(" width "+w);
System.out.println(" height "+h);
mView = new MyView(this, w, h);
mView.setDrawingCacheEnabled(true);
mView.invalidate();
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(Color.GREEN);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(5);
ImageButton coler = (ImageButton)findViewById(R.id.color);
coler.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int _color = R.color.red;
new ColorPickerDialog(v.getContext(),new OnColorChangedListener() {
public void colorChanged(int color) {
mPaint.setColor(color);
}
}, mPaint.getColor(), _color).show();
//new ColorPickerDialog(v.getContext(),new OnColorChangedListener(), mPaint.getColor(), _color).show();
}
});
ImageButton round = (ImageButton)findViewById(R.id.round);
round.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Small.this,Flipper.class);
startActivity(i);
}
});
relativelayout.addView(mView);
}
/////// colour changed function, getting value from ColorPickerDialog ///////
public void colorChanged(int color) {
mPaint.setColor(color);
}
private void setimage(int i) {
present = i;
switch(i) {
case 1:
imageview.setBackgroundResource(R.drawable.a);
imageview1.setBackgroundResource(R.drawable.arrow27);
break;
case 2:
imageview.setBackgroundResource(R.drawable.b);
imageview1.setBackgroundResource(R.drawable.arrow28);
break;
flipper.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="@+id/viewFlipper" android:layout_width="match_parent"
android:layout_height="fill_parent" >
</ViewFlipper>
<LinearLayout
android:id="@+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/round"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/round" />
</LinearLayout>
</RelativeLayout>
flipper.java
public class Flipper extends Activity implements OnClickListener {
/** Called when the activity is first created. */
ViewFlipper Flipp;
public int[][] img_array=new int[][]{
{R.drawable.flipimage_1_1,R.drawable.flipimage_1_2,R.drawable.flipimage_1_3, R.drawable.flipimage_1_4,R.drawable.flipimage_1_5,R.drawable.flipimage_1_6},
{R.drawable.flipimage_2_1,R.drawable.flipimage_2_2,R.drawable.flipimage_2_3, R.drawable.flipimage_2_4},
{R.drawable.flipimage_3_1,R.drawable.flipimage_3_2,R.drawable.flipimage_3_3, R.drawable.flipimage_3_4},
{R.drawable.flipimage_4_1,R.drawable.flipimage_4_2,R.drawable.flipimage_4_3, R.drawable.flipimage_4_4},
{R.drawable.flipimage_5_1,R.drawable.flipimage_5_2,R.drawable.flipimage_5_3, R.drawable.flipimage_5_4},
{R.drawable.flipimage_6_1,R.drawable.flipimage_6_2,R.drawable.flipimage_6_3, R.drawable.flipimage_6_4},
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.flipper);
Intent intent=getIntent();
int selected=intent.getIntExtra("SELECTED", 0);
int[] imgIds=img_array[selected];
Flipp = (ViewFlipper)findViewById(R.id.viewFlipper);
for(int i=0; i<imgIds.length;i++)
{
ImageView imgView=new ImageView(this);
imgView.setImageResource(imgIds[i]);
Flipp.addView(imgView);
}
Flipp.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
Flipp.showNext();
ImageButton round = (ImageButton)findViewById(R.id.round);
round.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
//Intent i = new Intent(Flipper.this,Small.class);
//startActivity(i);
}
});
}
}
答案 0 :(得分:2)
我假设要在鳍状肢上显示的图像点击a-a1,a2。在B-b1,b2 ......等等。将您的代码更改为以下
小班:
public class Small extends Activity {
// Instance variables
private Paint mPaint,mBitmapPaint;
private MyView mView;
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
public View onDraw;
private ImageView imageview;
private ImageView imageview1;
private ImageButton forword;
private ImageButton back;
private RelativeLayout relativelayout;
private int present;
protected int past;
protected int future;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.small);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
imageview = (ImageView)findViewById(R.id.image);
imageview1 = (ImageView)findViewById(R.id.ic_launcer);
forword = (ImageButton)findViewById(R.id.forword);
back = (ImageButton)findViewById(R.id.back);
relativelayout = (RelativeLayout)findViewById(R.id.item);
//select_color = (ImageButton) findViewById(R.id.color);
DisplayMetrics metrics = getBaseContext().getResources().getDisplayMetrics();
int w = metrics.widthPixels;
int h = metrics.heightPixels;
System.out.println(" width "+w);
System.out.println(" height "+h);
mView = new MyView(this, w, h);
mView.setDrawingCacheEnabled(true);
mView.invalidate();
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(Color.GREEN);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(5);
present = 1;
setimage(present);
back.setEnabled(false);
back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
past = present -1;
future = present +1;
if (past==1) {
back.setEnabled(false);
}else {
back.setEnabled(true);
}
if(past<=25) forword.setEnabled(true);
setimage(past);
System.out.println("pastvalue"+past);
}
});
forword.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
past = present -1;
future = present+1;
if(future==26){
forword.setEnabled(false);
}else {
forword.setEnabled(true);
}
if(future>=2) back.setEnabled(true);
setimage(future);
System.out.println("futurevalue"+future);
}
});
ImageButton coler = (ImageButton)findViewById(R.id.color);
coler.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int _color = R.color.red;
new ColorPickerDialog(v.getContext(),new OnColorChangedListener() {
public void colorChanged(int color) {
mPaint.setColor(color);
}
}, mPaint.getColor(), _color).show();
//new ColorPickerDialog(v.getContext(),new OnColorChangedListener(), mPaint.getColor(), _color).show();
}
});
ImageButton round = (ImageButton)findViewById(R.id.round);
round.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Small.this,Flipper.class);
i.putExtra("SELECTED", present);
startActivity(i);
}
});
relativelayout.addView(mView);
}
/////// colour changed function, getting value from ColorPickerDialog ///////
public void colorChanged(int color) {
mPaint.setColor(color);
}
private void setimage(int i) {
present = i;
switch(i) {
case 1:
imageview.setBackgroundResource(R.drawable.a);
imageview1.setBackgroundResource(R.drawable.arrow27);
break;
case 2:
imageview.setBackgroundResource(R.drawable.b);
imageview1.setBackgroundResource(R.drawable.arrow28);
break;
case 3:
imageview.setBackgroundResource(R.drawable.c);
imageview1.setBackgroundResource(R.drawable.arrow29);
break;
case 4:
imageview.setBackgroundResource(R.drawable.d);
imageview1.setBackgroundResource(R.drawable.arrow30);
break;
case 5:
imageview.setBackgroundResource(R.drawable.e);
imageview1.setBackgroundResource(R.drawable.arrow31);
break;
case 6:
imageview.setBackgroundResource(R.drawable.f);
imageview1.setBackgroundResource(R.drawable.arrow32);
break;
case 7:
imageview.setBackgroundResource(R.drawable.g);
imageview1.setBackgroundResource(R.drawable.arrow33);
break;
case 8:
imageview.setBackgroundResource(R.drawable.h);
imageview1.setBackgroundResource(R.drawable.arrow34);
break;
case 9:
imageview.setBackgroundResource(R.drawable.i);
imageview1.setBackgroundResource(R.drawable.arrow35);
break;
case 10:
imageview.setBackgroundResource(R.drawable.j);
imageview1.setBackgroundResource(R.drawable.arrow36);
break;
case 11:
imageview.setBackgroundResource(R.drawable.k);
imageview1.setBackgroundResource(R.drawable.arrow37);
break;
case 12:
imageview.setBackgroundResource(R.drawable.l);
imageview1.setBackgroundResource(R.drawable.arrow38);
break;
case 13:
imageview.setBackgroundResource(R.drawable.m);
imageview1.setBackgroundResource(R.drawable.arrow39);
break;
case 14:
imageview.setBackgroundResource(R.drawable.n);
imageview1.setBackgroundResource(R.drawable.arrow40);
break;
case 15:
imageview.setBackgroundResource(R.drawable.o);
imageview1.setBackgroundResource(R.drawable.arrow41);
break;
case 16:
imageview.setBackgroundResource(R.drawable.p);
imageview1.setBackgroundResource(R.drawable.arrow42);
break;
case 17:
imageview.setBackgroundResource(R.drawable.q);
imageview1.setBackgroundResource(R.drawable.arrow43);
break;
case 18:
imageview.setBackgroundResource(R.drawable.r);
imageview1.setBackgroundResource(R.drawable.arrow44);
break;
case 19:
imageview.setBackgroundResource(R.drawable.s);
imageview1.setBackgroundResource(R.drawable.arrow45);
break;
case 20:
imageview.setBackgroundResource(R.drawable.t);
imageview1.setBackgroundResource(R.drawable.arrow46);
break;
case 21:
imageview.setBackgroundResource(R.drawable.u);
imageview1.setBackgroundResource(R.drawable.arrow47);
break;
case 22:
imageview.setBackgroundResource(R.drawable.v);
imageview1.setBackgroundResource(R.drawable.arrow48);
break;
case 23:
imageview.setBackgroundResource(R.drawable.w);
imageview1.setBackgroundResource(R.drawable.arrow49);
break;
case 24:
imageview.setBackgroundResource(R.drawable.x);
imageview1.setBackgroundResource(R.drawable.arrow50);
break;
case 25:
imageview.setBackgroundResource(R.drawable.y);
imageview1.setBackgroundResource(R.drawable.arrow51);
break;
case 26:
imageview.setBackgroundResource(R.drawable.z);
imageview1.setBackgroundResource(R.drawable.arrow52);
break;
default:break;
}
}
}
注意我点击圆形时所做的更改。 Flipper.class:
public class ClassB extends Activity implements OnClickListener {
/** Called when the activity is first created. */
ViewFlipper Flipp;
public int[][] img_array=new int[][]{
{R.drawable.flipimage_1_1, R.drawable.flipimage_1_2}, {R.drawable.flipimage_2_1, R.drawable.flipimage_2_2}.....
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.flipper);
Intent intent=getIntent();
int selected=intent.getIntExtra("SELECTED", 0);
int[] imgIds=img_array[selected];
Flipp = (ViewFlipper)findViewById(R.id.viewFlipper);
for(int i=0; i<imgIds.length;i++)
{
ImageView imgView=new ImageView(this);
imgView.setImageResource(imgIds[i]);
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
Flipp.addView(imgView);
}
Flipp.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
Flipp.showNext();
ImageButton round = (ImageButton)findViewById(R.id.round);
round.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
//Intent i = new Intent(Flipper.this,Small.class);
//startActivity(i);
}
});
从xml中删除imageviews:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="@+id/viewFlipper" android:layout_width="match_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/imageview1" android:background="@drawable/flipimage_1_1" />
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/imageview2" android:background="@drawable/flipimage_1_2" />
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/imageview3" android:background="@drawable/flipimage_2_1" />
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/imageview4" android:background="@drawable/flipimage_2_2" />
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/imageview5" android:background="@drawable/flipimage_3_1" />
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/imageview6" android:background="@drawable/flipimage_3_2" />
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/imageview7" android:background="@drawable/flipimage_4_1" />
<ImageView
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/imageview8" android:background="@drawable/flipimage_4_2" />
</ViewFlipper>
<LinearLayout
android:id="@+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/round"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/round" />
</LinearLayout>
答案 1 :(得分:1)
据推测,您想要调用Path.reset,而不是Path.isEmpty;后者只是告诉你路径是否为空(而你的代码只是丢弃结果),它实际上并没有清空路径
答案 2 :(得分:0)
我会找到我的答案,我只是使用这个我的油漆视图是擦除
mBitmap.eraseColor(Color.TRANSPARENT);
mPath.reset();
mView.invalidate();