欢迎您光临深圳塔灯网络科技有限公司!
电话图标 余先生:13699882642

网站百科

为您解码网站建设的点点滴滴

ImageView 自适应手机屏幕 + 旋转

发表日期:2019-09 文章编辑:小灯 浏览次数:774

Chart.java

public class Chart extends VLinearLayout implements BaseView{private Activity context;private ImageView m_ImageView;private Bitmap img;private int ScaleAngle = 0; private Button turnLeft,turnRight;private HLinearLayout B_LinearLayout;private int[] WindowXY = new int[2];public Chart(Activity context) {super(context);this.context = context;m_ImageView = new ImageView(context);DisplayMetrics dm = new DisplayMetrics();context.getWindowManager().getDefaultDisplay().getMetrics(dm);WindowXY[0] = dm.widthPixels;WindowXY[1] = dm.heightPixels;B_LinearLayout = new HLinearLayout(context);turnLeft = new Button(context);turnLeft.setText("左转");turnRight = new Button(context);turnRight.setText("右转");turnLeft.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {turnLeft();}});turnRight.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {turnRight();}});B_LinearLayout.addView(turnLeft);turnLeft.setPadding(10, 5, 10, 5);B_LinearLayout.addView(turnRight);turnRight.setPadding(10, 5, 10, 5);this.addView(B_LinearLayout);this.addView(m_ImageView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));}public void turnLeft(){ScaleAngle--; int bmpWidth = img.getWidth();int bmpHeight = img.getHeight();Matrix matrix = new Matrix(); matrix.setRotate( 90 * ScaleAngle); Bitmap newBit = Bitmap.createBitmap(img, 0, 0, bmpWidth, bmpHeight, matrix, true);m_ImageView.setImageBitmap(newBit);}public void turnRight(){ScaleAngle++; int bmpWidth = img.getWidth();int bmpHeight = img.getHeight(); Matrix matrix = new Matrix(); matrix.setRotate( 90 * ScaleAngle); Bitmap newBit = Bitmap.createBitmap(img, 0, 0, bmpWidth, bmpHeight, matrix, true);m_ImageView.setImageBitmap(newBit);}public void setImage(String param){if (param == null || param.equals("")){Log.v("default", "image");try {img = BitmapFactory.decodeStream(context.getResources().getAssets().open("test.png"));} catch (IOException e) {Log.e("读取Assets下图片资源失败!", e.getMessage(), e);}}else{if (param.startsWith("/")) {img = BitmapFactory.decodeStream(ImageUtil.class.getResourceAsStream(param));} else if (param.startsWith("res-img:")) {try {img = BitmapFactory.decodeStream(context.getResources().getAssets().open(param.substring(8)));} catch (IOException e) {Log.e("读取Assets下图片资源失败!", e.getMessage(), e);}} else if (param.startsWith("stream:")) {String s = param.substring(7);img = BitmapFactory.decodeStream(new java.io.ByteArrayInputStream(StringUtil.fromBase64(s)));}}int bmpWidth = img.getWidth();int bmpHeight = img.getHeight();Log.v("base", bmpWidth+"");Log.v("base", bmpHeight+"");if(bmpWidth < WindowXY[0] && bmpHeight < WindowXY[1]){Matrix matrix = new Matrix(); float one = (float)WindowXY[0]/bmpWidth;float two = (float)WindowXY[1]/bmpHeight;Log.v("one", one+"");Log.v("two", two+"");if(one < two){Log.v("one", one+"");matrix.postScale(one, one);}else{Log.v("two", two+"");matrix.postScale(two, two);}img = Bitmap.createBitmap(img, 0, 0, bmpWidth, bmpHeight, matrix, true);}m_ImageView.setImageBitmap(img);}@Overridepublic String getValue() {return null;}@Overridepublic void setValue(String text) {}@Overridepublic View getView() {return this;}}
 
本页内容由塔灯网络科技有限公司通过网络收集编辑所得,所有资料仅供用户学习参考,本站不拥有所有权,如您认为本网页中由涉嫌抄袭的内容,请及时与我们联系,并提供相关证据,工作人员会在5工作日内联系您,一经查实,本站立刻删除侵权内容。本文链接:http://dengtar.com/20950.html
相关企业建站知识
 八年  行业经验

多一份参考,总有益处

联系深圳网站公司塔灯网络,免费获得网站建设方案及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:余经理:13699882642

Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.