FramLayout、图片旋转、(Horizonal)ScrollView、重绘图片(Canvas)、gallery、Activity调用
首先有一个自己的Rectangle,里面静态保存绘图痛的paint
1 package com.example.rotate; 2 3 import android.graphics.Color; 4 import android.graphics.Paint; 5 import android.graphics.Point; 6 import android.graphics.Rect; 7 import android.widget.SlidingDrawer; 8 9 public class MyRectangle { 10 static Paint circle_paint,line_paint,rectangle_paint; 11 Point begin_point,end_point; 12 Rect rectangle; 13 static{ 14 final int alpha=100,stroke_width=2; 15 circle_paint=new Paint(); 16 line_paint=new Paint(); 17 rectangle_paint=new Paint(); 18 circle_paint.setColor(Color.WHITE); 19 circle_paint.setStrokeWidth(stroke_width); 20 line_paint.setColor(Color.BLUE); 21 line_paint.setStrokeWidth(stroke_width); 22 line_paint.setAlpha(1); 23 rectangle_paint.setColor(Color.BLUE); 24 rectangle_paint.setStrokeWidth(stroke_width); 25 rectangle_paint.setAlpha(alpha); 26 } 27 public MyRectangle() 28 { 29 begin_point=new Point(); 30 begin_point=new Point(); 31 rectangle=new Rect(begin_point.x,begin_point.y,end_point.x,end_point.y); 32 } 33 MyRectangle(Point a,Point b) 34 { 35 begin_point=new Point(a); 36 end_point=new Point(b); 37 rectangle=new Rect(begin_point.x,begin_point.y,end_point.x,end_point.y); 38 } 39 }
然后是一个activity(主调Activity),里面涉及图片旋转,为gallery添加适配器(ImageAdapter集成BaseAdapter),
还用到另外ScrollView。
1 package com.example.rotate; 2 3 import java.util.ArrayList; 4 import java.util.LinkedList; 5 import java.util.List; 6 7 import android.opengl.Visibility; 8 import android.os.Bundle; 9 import android.app.ActionBar.LayoutParams; 10 import android.app.Activity; 11 import android.app.AlertDialog; 12 import android.content.Context; 13 import android.content.DialogInterface; 14 import android.content.Intent; 15 import android.content.res.TypedArray; 16 import android.graphics.Bitmap; 17 import android.graphics.BitmapFactory; 18 import android.graphics.Canvas; 19 import android.graphics.Color; 20 import android.graphics.Matrix; 21 import android.graphics.Paint; 22 import android.graphics.Paint.Style; 23 import android.graphics.Point; 24 import android.graphics.Rect; 25 import android.util.Log; 26 import android.view.Menu; 27 import android.view.MotionEvent; 28 import android.view.View; 29 import android.view.View.OnClickListener; 30 import android.view.View.OnTouchListener; 31 import android.view.ViewGroup; 32 import android.view.Window; 33 import android.view.WindowManager; 34 import android.widget.AdapterView; 35 import android.widget.AdapterView.OnItemSelectedListener; 36 import android.widget.BaseAdapter; 37 import android.widget.Gallery; 38 import android.widget.ImageButton; 39 import android.widget.ImageView; 40 import android.widget.LinearLayout; 41 import android.widget.TextView; 42 import android.widget.Toast; 43 44 public class MainActivity extends Activity implements OnItemSelectedListener,OnClickListener,OnTouchListener{ 45 public static final int ROTATE=1,DRAW=2,NULL=0,SMALL=3,BIG=4; 46 int state=NULL,image_position=0,image_state=SMALL; 47 List<Integer> image_id_list=new ArrayList<Integer>(); 48 Point begin_point,end_point; 49 private LinearLayout inner_layout,layout_in_innerlayout; 50 private ImageView image; 51 private ImageButton rotate_button,draw_button,trans_state; 52 private Gallery gallery; 53 static Bitmap ori_bitmap; 54 Bitmap cur_bitmap; 55 public boolean first_click=true; 56 @Override 57 protected void onCreate(Bundle savedInstanceState) { 58 super.onCreate(savedInstanceState); 59 requestWindowFeature(Window.FEATURE_NO_TITLE); 60 ViewGroup layout=(ViewGroup)getLayoutInflater().inflate(R.layout.activity_main, null); 61 setContentView(layout); 62 rotate_button=(ImageButton)findViewById(R.id.rotate); 63 rotate_button.setOnClickListener(this); 64 trans_state=(ImageButton)findViewById(R.id.trans_state); 65 trans_state.setOnClickListener(this); 66 draw_button=(ImageButton)findViewById(R.id.draw); 67 draw_button.setOnClickListener(this); 68 image_id_list.clear(); 69 image_id_list.add(R.drawable.image0); 70 image_id_list.add(R.drawable.image1); 71 image_id_list.add(R.drawable.image2); 72 image_id_list.add(R.drawable.image4); 73 image_id_list.add(R.drawable.image5); 74 image_id_list.add(R.drawable.image6); 75 image_id_list.add(R.drawable.image7); 76 image_id_list.add(R.drawable.image8); 77 inner_layout=(LinearLayout)findViewById(R.id.inner_layout); 78 inner_layout.setVisibility(View.INVISIBLE); 79 layout_in_innerlayout=(LinearLayout)findViewById(R.id.layout_in_innerlayout); 80 layout_in_innerlayout.setVisibility(View.INVISIBLE); 81 gallery=(Gallery)findViewById(R.id.image_switcher); 82 gallery.setAdapter(new ImageAdapter(this)); 83 gallery.setOnItemSelectedListener(this); 84 image=(ImageView)findViewById(R.id.small_image); 85 image.setOnClickListener(this); 86 image.setOnTouchListener(this); 87 } 88 @Override 89 public boolean onCreateOptionsMenu(Menu menu) { 90 if(layout_in_innerlayout.getVisibility()==View.VISIBLE) 91 layout_in_innerlayout.setVisibility(View.INVISIBLE); 92 else 93 layout_in_innerlayout.setVisibility(View.VISIBLE); 94 return false; 95 } 96 public class ImageAdapter extends BaseAdapter{ 97 private Context context; 98 public ImageAdapter(Context context) 99 { 100 this.context = context; 101 } 102 public int getCount() {return 100000;} 103 public Object getItem(int position) {return position%image_id_list.size();} 104 public long getItemId(int pos) {return pos%image_id_list.size();} 105 public View getView(int position, View arg1, ViewGroup arg2) { 106 ImageView image_view=new ImageView(context); 107 image_view.setImageResource(image_id_list.get(position%image_id_list.size())); 108 image_view.setScaleType(ImageView.ScaleType.FIT_CENTER); 109 image_view.setAdjustViewBounds(true); 110 image_view.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT)); 111 return image_view; 112 } 113 } 114 @Override 115 public void onItemSelected(AdapterView<?> arg0, View arg1, int position, 116 long arg3) { 117 image.setImageResource(image_id_list.get(position%image_id_list.size())); 118 image_position=position%image_id_list.size(); 119 cur_bitmap=BitmapFactory.decodeResource(getResources(), image_id_list.get(position%image_id_list.size())); 120 ori_bitmap=cur_bitmap.createBitmap(cur_bitmap); 121 rotate_degree=0; 122 } 123 void Reset() 124 { 125 WindowManager wm=getWindowManager(); 126 int height=wm.getDefaultDisplay().getHeight(),width=wm.getDefaultDisplay().getWidth(); 127 float scalx=(float)image.getWidth()/wm.getDefaultDisplay().getWidth(); 128 float scaly=(float)image.getHeight()/wm.getDefaultDisplay().getHeight(); 129 Matrix matrix=new Matrix(); 130 matrix.setScale(scalx, scaly); 131 Bitmap bitmap=Bitmap.createBitmap(cur_bitmap,0,0,image.getWidth(),image.getHeight(),matrix,true); 132 image.setImageBitmap(bitmap); 133 } 134 @Override 135 public void onNothingSelected(AdapterView<?> arg0) {} 136 public void onClick(View view) { 137 // TODO Auto-generated method stub 138 switch(view.getId()){ 139 case R.id.small_image:; 140 case R.id.image: 141 if(first_click){ 142 inner_layout.setVisibility(View.VISIBLE); 143 first_click=false; 144 } 145 else{ 146 inner_layout.setVisibility(View.INVISIBLE); 147 first_click=true; 148 }break; 149 case R.id.draw: 150 AlertDialog.Builder dialog=new AlertDialog.Builder(this); 151 dialog.setMessage("Constraint the ratio of Width and Height?"); 152 dialog.setNegativeButton("YES",new DialogInterface.OnClickListener() { 153 public void onClick(DialogInterface arg0, int arg1) { 154 DrawRectabgle.constraint_widthandheight=true; 155 Intent intent=new Intent(); 156 intent.setClass(MainActivity.this, DrawRectabgle.class); 157 DrawRectabgle.ori_bitmap=Bitmap.createBitmap(ori_bitmap); 158 startActivity(intent); 159 } 160 }); 161 dialog.setPositiveButton("NO", new DialogInterface.OnClickListener() { 162 public void onClick(DialogInterface arg0, int arg1) { 163 DrawRectabgle.constraint_widthandheight=false; 164 Intent intent=new Intent(); 165 intent.setClass(MainActivity.this, DrawRectabgle.class); 166 DrawRectabgle.ori_bitmap=Bitmap.createBitmap(ori_bitmap); 167 startActivity(intent); 168 } 169 }); 170 dialog.show(); 171 inner_layout.setVisibility(View.INVISIBLE); 172 first_click=true; 173 state=DRAW; 174 break; 175 case R.id.rotate: 176 inner_layout.setVisibility(View.INVISIBLE); 177 first_click=true; 178 state=ROTATE; 179 break; 180 case R.id.trans_state: 181 image.setVisibility(View.GONE); 182 if(image_state==SMALL) 183 { 184 image=(ImageView)findViewById(R.id.image); 185 image_state=BIG; 186 } 187 else 188 { 189 image=(ImageView)findViewById(R.id.small_image); 190 image_state=SMALL; 191 } 192 image.setImageResource(image_id_list.get(image_position)); 193 image.setImageBitmap(cur_bitmap); 194 image.setOnClickListener(this); 195 image.setOnTouchListener(this); 196 image.setVisibility(View.VISIBLE); 197 break; 198 case R.id.uncloclwise: 199 if(image_state==SMALL) 200 RotateImage(-1); 201 break; 202 case R.id.clockwise: 203 if(image_state==SMALL) 204 RotateImage(1); 205 break; 206 } 207 } 208 @Override 209 public boolean onTouch(View view, MotionEvent event) { 210 switch(state){ 211 case DRAW: 212 state=NULL; 213 return false; 214 case ROTATE: 215 if(image_state==SMALL) 216 { 217 switch(event.getAction()){ 218 case MotionEvent.ACTION_DOWN: 219 begin_point=new Point((int)event.getX(),(int)event.getY()); 220 return true; 221 case MotionEvent.ACTION_MOVE: 222 end_point=new Point((int)event.getX(),(int)event.getY()); 223 RotateImage(0); 224 begin_point=new Point(end_point); 225 return true; 226 case MotionEvent.ACTION_UP: 227 state=NULL; 228 return false; 229 default:return false; 230 } 231 } 232 } 233 return false; 234 } 235 int rotate_degree=0; 236 void RotateImage(int n) 237 { 238 Matrix matrix=new Matrix(); 239 int temp_degree; 240 if(n!=0) temp_degree=n; 241 else 242 { 243 int x0=image.getWidth()/2,y0=image.getHeight()/2; 244 int x1=begin_point.x-x0,y1=begin_point.y-y0; 245 int x2=end_point.x-x0,y2=end_point.y-y0; 246 double sina=(double)(x1*y2-x2*y1)/(Math.sqrt(x1*x1+y1*y1)*Math.sqrt(x2*x2+y2*y2)); 247 temp_degree=(int)(Math.asin(sina)*180/Math.PI); 248 } 249 rotate_degree+=temp_degree; 250 rotate_degree%=360; 251 matrix.setRotate(rotate_degree); 252 cur_bitmap=Bitmap.createBitmap(ori_bitmap, 0, 0, ori_bitmap.getWidth(), ori_bitmap.getHeight(),matrix,true); 253 image.setImageBitmap(cur_bitmap); 254 } 255 }
再然后这是一个被调的Activity。里面实现通过Canvas在已有的图片上画出图形(这里是矩形),并增加了一些其他功能,如对已存在的矩形进行增删
1 package com.example.rotate; 2 import java.util.LinkedList; 3 4 import android.view.Menu; 5 import android.view.MotionEvent; 6 import android.view.View; 7 import android.view.Window; 8 import android.view.View.OnClickListener; 9 import android.view.View.OnLongClickListener; 10 import android.view.View.OnTouchListener; 11 import android.view.WindowManager; 12 import android.app.Activity; 13 import android.app.AlertDialog; 14 import android.app.Dialog; 15 import android.content.DialogInterface; 16 import android.graphics.Bitmap; 17 import android.graphics.Canvas; 18 import android.graphics.Color; 19 import android.graphics.Matrix; 20 import android.graphics.Paint; 21 import android.graphics.Point; 22 import android.graphics.Rect; 23 import android.graphics.Paint.Style; 24 import android.os.Bundle; 25 import android.widget.HorizontalScrollView; 26 import android.widget.ImageView; 27 import android.widget.ScrollView; 28 public class DrawRectabgle extends Activity implements OnClickListener,OnTouchListener{ 29 static final int DRAW=1,DELETE=2; 30 public int image_state=DRAW; 31 public Bitmap cur_bitmap; 32 public static Bitmap ori_bitmap; 33 public static boolean constraint_widthandheight; 34 ImageView image; 35 HorizontalScrollView layout_draw; 36 LinkedList<MyRectangle> rectangle_list=new LinkedList<MyRectangle>(),back_rec_list=new LinkedList<MyRectangle>(); 37 Point begin_point,end_point,delete_point; 38 protected void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 requestWindowFeature(Window.FEATURE_NO_TITLE); 41 setContentView(R.layout.draw_rectangle); 42 rectangle_list.clear(); 43 back_rec_list.clear(); 44 image=(ImageView)findViewById(R.id.image_view); 45 image.setOnTouchListener(this); 46 image.setOnClickListener(this); 47 WindowManager wm=getWindowManager(); 48 float scal_width=(float)wm.getDefaultDisplay().getWidth()/ori_bitmap.getWidth(); 49 float scal_height=(float)wm.getDefaultDisplay().getHeight()/ori_bitmap.getHeight(); 50 float scal=scal_width>scal_height?scal_height:scal_width; 51 Matrix matrix=new Matrix(); 52 if(constraint_widthandheight) 53 matrix.postScale(scal,scal); 54 else 55 matrix.postScale(scal_width, scal_height); 56 ori_bitmap=Bitmap.createBitmap(ori_bitmap, 0, 0, ori_bitmap.getWidth(), ori_bitmap.getHeight(),matrix,true); 57 image.setImageBitmap(ori_bitmap); 58 cur_bitmap=Bitmap.createBitmap(ori_bitmap); 59 layout_draw=(HorizontalScrollView)findViewById(R.id.layout_of_drawrectangle); 60 layout_draw.setVisibility(View.INVISIBLE); 61 } 62 public boolean onCreateOptionsMenu(Menu menu) { 63 if(layout_draw.getVisibility()==View.INVISIBLE) 64 layout_draw.setVisibility(View.VISIBLE); 65 else 66 layout_draw.setVisibility(View.INVISIBLE); 67 return false; 68 } 69 public void onClick(View view) { 70 switch(view.getId()){ 71 case R.id.confirm: 72 if(image_state==DELETE) 73 image_state=DRAW; 74 break; 75 case R.id.back: 76 if(!rectangle_list.isEmpty()) 77 { 78 MyRectangle t=rectangle_list.getLast(); 79 rectangle_list.removeLast(); 80 back_rec_list.addLast(t); 81 DrawMyRectangle(); 82 } 83 break; 84 case R.id.forward: 85 if(!back_rec_list.isEmpty()) 86 { 87 MyRectangle t=back_rec_list.getLast(); 88 back_rec_list.removeLast(); 89 rectangle_list.addLast(t); 90 DrawMyRectangle(); 91 } 92 break; 93 case R.id.delete: 94 image_state=DELETE; 95 break; 96 case R.id.constraint_wh: 97 finish(); 98 break; 99 } 100 } 101 public boolean onTouch(View view, MotionEvent event) { 102 switch(event.getAction()){ 103 case MotionEvent.ACTION_DOWN: 104 if(image_state==DELETE) 105 delete_point=new Point((int)event.getX(),(int)event.getY()); 106 else{ 107 begin_point=new Point((int)event.getX(),(int)event.getY()); 108 layout_draw.setVisibility(View.INVISIBLE); 109 } 110 break; 111 case MotionEvent.ACTION_MOVE: 112 if(image_state==DELETE) 113 delete_point=new Point((int)event.getX(),(int)event.getY()); 114 else 115 { 116 end_point=new Point((int)event.getX(),(int)event.getY()); 117 DrawRect(); 118 } 119 break; 120 case MotionEvent.ACTION_UP: 121 if(image_state==DELETE) 122 { 123 delete_point=new Point((int)event.getX(),(int)event.getY()); 124 LinkedList<MyRectangle> temp_list=new LinkedList<MyRectangle>(); 125 temp_list.clear(); 126 for(MyRectangle ele: rectangle_list) 127 { 128 if(IsInRect(ele.begin_point,ele.end_point)) 129 { 130 back_rec_list.addLast(ele); 131 temp_list.addLast(ele); 132 } 133 } 134 rectangle_list.removeAll(temp_list); 135 } 136 else 137 { 138 end_point=new Point((int)event.getX(),(int)event.getY()); 139 if(LegalPoint()) 140 { 141 CheckPoint(); 142 rectangle_list.addLast(new MyRectangle(begin_point,end_point)); 143 } 144 layout_draw.setVisibility(View.VISIBLE); 145 } 146 DrawMyRectangle(); 147 } 148 return false; 149 } 150 public boolean LegalPoint() 151 { 152 int x=begin_point.x-end_point.x; 153 int y=begin_point.y-end_point.y; 154 return x*x+y*y>64; 155 } 156 public void DrawMyRectangle() 157 { 158 Bitmap temp_bitmap=Bitmap.createBitmap(cur_bitmap.getWidth(), cur_bitmap.getHeight(), cur_bitmap.getConfig()); 159 Canvas temp_canvas=new Canvas(temp_bitmap); 160 temp_canvas.drawBitmap(ori_bitmap,new Matrix(),new Paint()); 161 for(MyRectangle ele:rectangle_list) 162 { 163 temp_canvas.drawRect(ele.rectangle, ele.rectangle_paint); 164 temp_canvas.drawCircle(ele.begin_point.x, ele.begin_point.y, 8, ele.circle_paint); 165 temp_canvas.drawCircle(ele.end_point.x, ele.end_point.y, 8, ele.circle_paint); 166 temp_canvas.drawCircle(ele.begin_point.x, ele.end_point.y, 8, ele.circle_paint); 167 temp_canvas.drawCircle(ele.end_point.x, ele.begin_point.y, 8, ele.circle_paint); 168 } 169 cur_bitmap=temp_bitmap; 170 image.setImageBitmap(cur_bitmap); 171 } 172 public void DrawRect() 173 { 174 Bitmap temp_bitmap=Bitmap.createBitmap(cur_bitmap.getWidth(), cur_bitmap.getHeight(), cur_bitmap.getConfig()); 175 Canvas temp_canvas=new Canvas(temp_bitmap); 176 temp_canvas.drawBitmap(cur_bitmap, new Matrix(), new Paint()); 177 temp_canvas.drawRect(new Rect(begin_point.x,begin_point.y,end_point.x,end_point.y),MyRectangle.rectangle_paint); 178 image.setImageBitmap(temp_bitmap); 179 } 180 public boolean IsInRect(Point begin,Point end) 181 { 182 if(delete_point.x>begin.x&&delete_point.x<end.x) 183 if(delete_point.y>begin.y&&delete_point.y<end.y) 184 return true; 185 return false; 186 } 187 public void CheckPoint() 188 { 189 int x1=begin_point.x,y1=begin_point.y; 190 int x2=end_point.x,y2=end_point.y; 191 begin_point.x=x1<x2?x1:x2;end_point.x=x1>x2?x1:x2; 192 begin_point.y=y1<y2?y1:y2;end_point.y=y1>y2?y1:y2; 193 } 194 }
最后,这是一些布局文件(里面用到的图片这里就不解释了)一共两个
1 <?xml version="1.0" encoding="utf-8"?> 2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:background="#000000" 6 android:orientation="vertical" > 7 <ImageView 8 android:id="@+id/image_view" 9 android:layout_width="match_parent" 10 android:layout_height="match_parent" 11 android:scaleType="matrix" 12 android:layout_gravity="center|bottom" 13 android:src="@drawable/image5" /> 14 <HorizontalScrollView 15 android:id="@+id/layout_of_drawrectangle" 16 android:layout_gravity="bottom" 17 android:layout_width="match_parent" 18 android:background="#BFBFBF" 19 android:layout_height="50dp"> 20 <LinearLayout 21 android:layout_width="wrap_content" 22 android:layout_height="match_parent" 23 android:background="#BFBFBF" 24 android:orientation="horizontal"> 25 <ImageButton 26 android:id="@+id/constraint_wh" 27 android:layout_width="80dp" 28 android:layout_height="match_parent" 29 android:onClick="onClick" 30 android:background="#BFBFBF" 31 android:scaleType="fitCenter" 32 android:src="@drawable/trans_state"/> 33 <ImageButton 34 android:id="@+id/confirm" 35 android:layout_width="80dp" 36 android:layout_height="match_parent" 37 android:onClick="onClick" 38 android:background="#BFBFBF" 39 android:src="@drawable/confirm"/> 40 <ImageButton 41 android:id="@+id/back" 42 android:layout_width="80dp" 43 android:background="#BFBFBF" 44 android:layout_height="match_parent" 45 android:onClick="onClick" 46 android:src="@drawable/back" /> 47 <ImageButton 48 android:id="@+id/forward" 49 android:layout_width="80dp" 50 android:layout_height="match_parent" 51 android:background="#BFBFBF" 52 android:onClick="onClick" 53 android:src="@drawable/forward"/> 54 <ImageButton 55 android:id="@+id/delete" 56 android:layout_width="80dp" 57 android:layout_height="match_parent" 58 android:background="#BFBFBF" 59 android:onClick="onClick" 60 android:src="@drawable/delete"/> 61 </LinearLayout> 62 63 </HorizontalScrollView> 64 </FrameLayout>
1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context=".MainActivity" > 6 <ScrollView 7 android:layout_width="match_parent" 8 android:layout_height="match_parent"> 9 <HorizontalScrollView 10 android:layout_width="match_parent" 11 android:layout_height="match_parent"> 12 <ImageView 13 android:id="@+id/image" 14 android:layout_width="match_parent" 15 android:layout_height="fill_parent" 16 android:background="#404040" 17 android:src="@drawable/image0" 18 android:scaleType="fitCenter"/> 19 </HorizontalScrollView> 20 </ScrollView> 21 <ImageView 22 android:id="@+id/small_image" 23 android:layout_width="match_parent" 24 android:layout_height="fill_parent" 25 android:background="#404040" 26 android:visibility="visible" 27 android:src="@drawable/image0" 28 android:scaleType="fitCenter"/> 29 <LinearLayout 30 android:id="@+id/inner_layout" 31 android:layout_width="fill_parent" 32 android:layout_height="120dp" 33 android:layout_marginBottom="0dp" 34 android:layout_gravity="bottom" 35 android:orientation="vertical" 36 android:visibility="visible"> 37 <LinearLayout 38 android:id="@+id/layout_in_innerlayout" 39 android:layout_width="match_parent" 40 android:layout_height="50dp" 41 android:background="#BFBFBF" 42 android:orientation="horizontal"> 43 <ImageButton 44 android:id="@+id/rotate" 45 android:layout_width="wrap_content" 46 android:layout_height="match_parent" 47 android:background="#BFBFBF" 48 android:src="@drawable/rotate"/> 49 <ImageButton 50 android:id="@+id/draw" 51 android:layout_width="wrap_content" 52 android:layout_height="match_parent" 53 android:background="#BFBFBF" 54 android:src="@drawable/draw"/> 55 56 <ImageButton 57 android:id="@+id/uncloclwise" 58 android:layout_width="46dp" 59 android:layout_height="match_parent" 60 android:background="#BFBFBF" 61 android:scaleType="fitCenter" 62 android:onClick="onClick" 63 android:src="@drawable/unclockwise" /> 64 65 <ImageButton 66 android:id="@+id/clockwise" 67 android:layout_width="46dp" 68 android:layout_height="match_parent" 69 android:background="#BFBFBF" 70 android:scaleType="fitCenter" 71 android:onClick="onClick" 72 android:src="@drawable/clockwise" /> 73 74 <ImageButton 75 android:id="@+id/trans_state" 76 android:layout_width="wrap_content" 77 android:layout_height="match_parent" 78 android:background="#BFBFBF" 79 android:scaleType="fitCenter" 80 android:src="@drawable/trans_state"/> 81 </LinearLayout> 82 <Gallery 83 android:id="@+id/image_switcher" 84 android:layout_width="match_parent" 85 android:layout_height="70dp" 86 android:background="#000000" 87 android:layout_marginBottom="0dp"></Gallery> 88 </LinearLayout> 89 90 91 </FrameLayout>
总结:
1、活动相互调用时要记得修改Manifeast文件;
2、活动之间相互传递信息的一种方法:将其中一个activity中的数据类型设置成static,然后在另外一个中通过类名进行调用;
3、在一个图片上绘制图形的过程:建一个新的Bitmap bitmap=Bitmap.createBitmap(ori_bitmap,width,height,config)、建Canvas canvas=new Canvas(bitmap)、画Bitmap:canvas.drawBitmap(ori_bitmap,new Matrix(),new Paint())、画其他图形……、重置ImageView的Bitmap:image.setImageBitmap(bitmap)。搞定!

浙公网安备 33010602011771号