android 中View.setID,与getID

private Map<String, TextView> mapBt = new HashMap<String, TextView>();

bt.setOnClickListener(new OnClickListener() {


@Override

public void

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.blog.dragview; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.os.Bundle; import android.util.Log; import com.blog.R; import org.json.JSONArray; import org.json.JSONException; import java.util.List; public class MainActivity extends Activity{ private DrawingView _view; @Override protected void onCreate(Bundle savedInstanceState) { _view = new DrawingView(this); super.onCreate(savedInstanceState); setContentView(_view); Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.hengzhegou); Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),R.drawable.pie); CustomBitmap customBitmap1 = new CustomBitmap(bmp1); CustomBitmap customBitmap2 = new CustomBitmap(bmp2); customBitmap1.setId(1); customBitmap2.setId(2); if (getSavedMatrix(1) != null){ Log.e("tag", "matrix 1 is not null"); customBitmap1.setMatrix(getSavedMatrix(1)); } if (getSavedMatrix(2) != null){ Log.e("tag", "matrix 2 is not null"); customBitmap2.setMatrix(getSavedMatrix(2)); } _view.addBitmap(customBitmap1); _view.addBitmap(customBitmap2); } //����matrix private void saveMatrix(CustomBitmap customBitmap){ Log.e("tag", "save matrix" + customBitmap.getId()); SharedPreferences.Editor editor = getSharedPreferences("matrix", Context.MODE_PRIVATE).edit(); Matrix matrix = customBitmap.matrix; float[] values = new float[9]; matrix.getValues(values); JSONArray array = new JSONArray(); for (float value:values){ try { array.put(value); } catch (JSONException e) { e.printStackTrace(); } } editor.putString(String.valueOf(customBitmap.getId()), array.toString()); editor.commit(); Log.e("tag", "save matrix id:" + customBitmap.getId() + "---------"+values[Matrix.MPERSP_0] + " , " + values[Matrix.MPERSP_1] + " , " + values[Matrix.MPERSP_2] + " , " + values[Matrix.MSCALE_X] + " , " + values[Matrix.MSCALE_Y] + " , " + values[Matrix.MSKEW_X] + " , " + values[Matrix.MSKEW_Y] + " , " +values[Matrix.MTRANS_X] + " , " + values[Matrix.MTRANS_Y]); } //��ȡmatrix private Matrix getSavedMatrix(int id){ SharedPreferences sp = getSharedPreferences("matrix", Context.MODE_PRIVATE); String result = sp.getString(String.valueOf(id), null); if (result != null){ float[] values = new float[9]; Matrix matrix = new Matrix(); try { JSONArray array = new JSONArray(result); for (int i = 0; i < array.length(); i++) { values[i] = Float.valueOf(String.valueOf(array.getDouble(i))); } matrix.setValues(values); } catch (JSONException e) { e.printStackTrace(); } Log.e("tag", "get matrix id:" + id + "---------"+values[Matrix.MPERSP_0] + " , " + values[Matrix.MPERSP_1] + " , " + values[Matrix.MPERSP_2] + " , " + values[Matrix.MSCALE_X] + " , " + values[Matrix.MSCALE_Y] + " , " + values[Matrix.MSKEW_X] + " , " + values[Matrix.MSKEW_Y] + " , " +values[Matrix.MTRANS_X] + " , " + values[Matrix.MTRANS_Y]); return matrix ; } return null; } @Override public void finish() { List<CustomBitmap> list = _view.getViews(); for (CustomBitmap customBitmap:list){ saveMatrix(customBitmap); } super.finish(); } }
最新发布
06-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值