当前位置:首页 » 安卓系统 » android缩放

android缩放

发布时间: 2022-01-11 03:29:20

Ⅰ Android 编程 如何实现 文字放大效果 例如图片的放大和缩小的效果

这种功能需要使用print绘制,然后通过多点触控事件来自行计算用户是需要放大还是缩小,然后对应的去设置文字大小

Ⅱ 有谁知道怎么实现android界面整体缩放

android界面实现整体缩放
代码:
float basevectorX = 0.0f
float basevectorY = 0.0f
//浮点坐标 左上角坐标
float FfrogX = 0.0f;
float FfrogY = 0.0f;
//整形坐标 左上角坐标
int frogX = 0;
int frogY = 0;

Rect rect = new Rect();
FfrogX = FfrogX+basevectorX;
frogX = (int)FfrogX;
FfrogY = FfrogY+basevectorY;
frogY = (int) FfrogY;
rect.left= frogX;
rect.right= ScreenWidth-rect.left-Width; //640
rect.top= frogY; //480
rect.bottom= ScreenHeight-rect.top-Height; //480
((MarginLayoutParams) frogview.getLayoutParams()).setMargins(rect.left, rect.top, rect.right, rect.bottom);
//这个可以放 大缩小,和移动。
CenterX = rect.left + Width/2; //中心点X坐标 用来判断的 用于2d
CenterY = rect.top + Height/2; //中心点Y坐标 用来判断的 用于2d

Ⅲ Android 手势缩放一个布局,布局里面有控件,跟随缩放,求demo

给出思路:
在代码中获得要旋转的布局;
监听布局的OnTouch事件;
当触发滑动事件后,创建一个旋转动画,将动画赋予布局;
布局中的控件注册自己的监听器,跟这个旋转没有影响。
这个是我想到的,没试验,题主可以试试。
有疑问,请追问。望采纳!

Ⅳ android 如何实现对view的放大和缩小

图片放大缩小方法如下:

图片放大缩小就是使用Matrix类,而这里通过手势控制,那自然是需要监听onTouch事件,所以原理简单来说,就是通过监听onTouch的各种事件来控制Matrix类了。

java">{
privatefinalstaticStringTAG="MatrixImageView";
;
/**模板Matrix,用以初始化*/
privateMatrixmMatrix=newMatrix();
/**图片长度*/
privatefloatmImageWidth;
/**图片高度*/
privatefloatmImageHeight;

publicMatrixImageView(Contextcontext,AttributeSetattrs){
super(context,attrs);
MatrixTouchListenermListener=newMatrixTouchListener();
setOnTouchListener(mListener);
mGestureDetector=newGestureDetector(getContext(),newGestureListener(mListener));
//背景设置为balck
setBackgroundColor(Color.BLACK);
//将缩放类型设置为FIT_CENTER,表示把图片按比例扩大/缩小到View的宽度,居中显示
setScaleType(ScaleType.FIT_CENTER);
}

Ⅳ 求一个实现android布局文件整体缩放的实现方法

题主可以先继承布局类,如另写一个类继承LineatLayout ,然后实现onMeasure()方法,在方法里面获取布局的宽度和高度,再根据获取到的宽度和高度 设置控件内元素的宽高,比如元素Title的高 TitleHeight = measureHeight *0.5 ,意思是占布局高的二分之一,这时就可以整体缩放了。
onmeasure()内获取宽高的方法:
int measureWidth = measureWidth(widthMeasureSpec);
int measureHeight = measureHeight(heightMeasureSpec);

其中宽度的函数:
private int measureWidth(int widthMeasureSpec) {
int specMode = MeasureSpec.getMode(widthMeasureSpec);
int specSize = MeasureSpec.getSize(widthMeasureSpec);
int result = 500;
if (specMode == MeasureSpec.AT_MOST) {
result = specSize;
} else if (specMode == MeasureSpec.EXACTLY) {
result = specSize;
}
return result;
}

Ⅵ android等比例缩放图片的方法

itmap icon = null;//原始图片
int width = icon.getWidth(), height = icon.getHeight();
float scaleRate = 0.8f;//缩小的比例
while(width >= 300 || width >= 300) {
Matrix matrix = new Matrix();
matrix.postScale(width * scaleRate, height * scaleRate);
// 得到新的图片
Bitmap newIcon = Bitmap.createBitmap(icon, 0, 0, width, height, matrix, true);
icon.recycle();
icon = newIcon;
width = icon.getWidth(), height = icon.getHeight();
}int width = icon.getWidth(), height = icon.getHeight();

if(width > 300 || width > 300) {
float scaleRate = width > height ? 300 / width : 300 / height;
Matrix matrix = new Matrix();
matrix.postScale(width * scaleRate, height * scaleRate);
// 得到新的图片
Bitmap newIcon = Bitmap.createBitmap(icon, 0, 0, width, height, matrix, true);
icon.recycle();
icon = newIcon;
}

Ⅶ 如何通过手势实现android view 的 缩放 平移

代码主要分两部分,一个activity一个view,代码如下:

packagecom.example.touch;

importandroid.app.Activity;
importandroid.os.Bundle;

{
/**.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
TouchImageViewimg=newTouchImageView(this);
setContentView(img);
}
}



packagecom.example.touch;

importandroid.graphics.Bitmap;
importandroid.graphics.Bitmap.Config;
importandroid.graphics.BitmapFactory;
importandroid.graphics.Canvas;
importandroid.graphics.Matrix;
importandroid.graphics.PointF;
importandroid.util.DisplayMetrics;
importandroid.util.FloatMath;
importandroid.view.MotionEvent;
importandroid.widget.ImageView;

{

floatx_down=0;
floaty_down=0;
PointFstart=newPointF();
PointFmid=newPointF();
floatoldDist=1f;
floatoldRotation=0;
Matrixmatrix=newMatrix();
Matrixmatrix1=newMatrix();
MatrixsavedMatrix=newMatrix();

privatestaticfinalintNONE=0;
privatestaticfinalintDRAG=1;
privatestaticfinalintZOOM=2;
intmode=NONE;

booleanmatrixCheck=false;

intwidthScreen;
intheightScreen;

Bitmapgintama;

publicTouchImageView(){
super(activity);
gintama=BitmapFactory.decodeResource(getResources(),R.drawable.gintama);

DisplayMetricsdm=newDisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
widthScreen=dm.widthPixels;
heightScreen=dm.heightPixels;

matrix=newMatrix();
}

protectedvoidonDraw(Canvascanvas){
canvas.save();
canvas.drawBitmap(gintama,matrix,null);
canvas.restore();
}

publicbooleanonTouchEvent(MotionEventevent){
switch(event.getAction()&MotionEvent.ACTION_MASK){
caseMotionEvent.ACTION_DOWN:
mode=DRAG;
x_down=event.getX();
y_down=event.getY();
savedMatrix.set(matrix);
break;
caseMotionEvent.ACTION_POINTER_DOWN:
mode=ZOOM;
oldDist=spacing(event);
oldRotation=rotation(event);
savedMatrix.set(matrix);
midPoint(mid,event);
break;
caseMotionEvent.ACTION_MOVE:
if(mode==ZOOM){
matrix1.set(savedMatrix);
floatrotation=rotation(event)-oldRotation;
floatnewDist=spacing(event);
floatscale=newDist/oldDist;
matrix1.postScale(scale,scale,mid.x,mid.y);//缩放
matrix1.postRotate(rotation,mid.x,mid.y);//旋转
matrixCheck=matrixCheck();
if(matrixCheck==false){
matrix.set(matrix1);
invalidate();
}
}elseif(mode==DRAG){
matrix1.set(savedMatrix);
matrix1.postTranslate(event.getX()-x_down,event.getY()
-y_down);//平移
matrixCheck=matrixCheck();
matrixCheck=matrixCheck();
if(matrixCheck==false){
matrix.set(matrix1);
invalidate();
}
}
break;
caseMotionEvent.ACTION_UP:
caseMotionEvent.ACTION_POINTER_UP:
mode=NONE;
break;
}
returntrue;
}

privatebooleanmatrixCheck(){
float[]f=newfloat[9];
matrix1.getValues(f);
//图片4个顶点的坐标
floatx1=f[0]*0+f[1]*0+f[2];
floaty1=f[3]*0+f[4]*0+f[5];
floatx2=f[0]*gintama.getWidth()+f[1]*0+f[2];
floaty2=f[3]*gintama.getWidth()+f[4]*0+f[5];
floatx3=f[0]*0+f[1]*gintama.getHeight()+f[2];
floaty3=f[3]*0+f[4]*gintama.getHeight()+f[5];
floatx4=f[0]*gintama.getWidth()+f[1]*gintama.getHeight()+f[2];
floaty4=f[3]*gintama.getWidth()+f[4]*gintama.getHeight()+f[5];
//图片现宽度
doublewidth=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
//缩放比率判断
if(width<widthScreen/3||width>widthScreen*3){
returntrue;
}
//出界判断
if((x1<widthScreen/3&&x2<widthScreen/3
&&x3<widthScreen/3&&x4<widthScreen/3)
||(x1>widthScreen*2/3&&x2>widthScreen*2/3
&&x3>widthScreen*2/3&&x4>widthScreen*2/3)
||(y1<heightScreen/3&&y2<heightScreen/3
&&y3<heightScreen/3&&y4<heightScreen/3)
||(y1>heightScreen*2/3&&y2>heightScreen*2/3
&&y3>heightScreen*2/3&&y4>heightScreen*2/3)){
returntrue;
}
returnfalse;
}

//触碰两点间距离
privatefloatspacing(MotionEventevent){
floatx=event.getX(0)-event.getX(1);
floaty=event.getY(0)-event.getY(1);
returnFloatMath.sqrt(x*x+y*y);
}

//取手势中心点
privatevoidmidPoint(PointFpoint,MotionEventevent){
floatx=event.getX(0)+event.getX(1);
floaty=event.getY(0)+event.getY(1);
point.set(x/2,y/2);
}

//取旋转角度
privatefloatrotation(MotionEventevent){
doubledelta_x=(event.getX(0)-event.getX(1));
doubledelta_y=(event.getY(0)-event.getY(1));
doubleradians=Math.atan2(delta_y,delta_x);
return(float)Math.toDegrees(radians);
}

//将移动,缩放以及旋转后的图层保存为新图片
//本例中没有用到该方法,需要保存图片的可以参考
publicBitmapCreatNewPhoto(){
Bitmapbitmap=Bitmap.createBitmap(widthScreen,heightScreen,
Config.ARGB_8888);//背景图片
Canvascanvas=newCanvas(bitmap);//新建画布
canvas.drawBitmap(gintama,matrix,null);//画图片
canvas.save(Canvas.ALL_SAVE_FLAG);//保存画布
canvas.restore();
returnbitmap;
}

}

Ⅷ Android怎样通过手势实现缩放处理

android开发是目前很热门的课程,我们要了解通过手势实现的缩放处理 的基础才可以更好的应用Android系统。import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.os.Bundle;import android.util.DisplayMetrics;import android.view.MotionEvent;import android.view.View;/*** ...** @author vlinux**/public class MultiTouchTestActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// setContentView(R.layout.main);View view = new MultiTouchView(this);setContentView(view);}class MultiTouchView extends View {private float x1;private float y1;private float x2;private float y2;public MultiTouchView(Context context) {super(context);// TODO Auto-generated constructor stub}@Overridepublic boolean onTouchEvent(MotionEvent event) {// TODO Auto-generated method stubfloat size = event.getSize();int szi = (int) size;int dxi = szi >> 12;int dyit = ((1 << 12) - 1);int dyi = szi & dyit;DisplayMetrics metrics = getResources().getDisplayMetrics();float dx = metrics.widthPixels * dxi / (float) dyit;float dy = metrics.heightPixels * dyi / (float) dyit;x1 = event.getX();y1 = event.getY();x2 = x1 + dx;y2 = y1 + dy;invalidate();return true;}@Overrideprotected void onDraw(Canvas canvas) {// TODO Auto-generated method stubsuper.onDraw(canvas);float r = (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2)* (y1 - y2)) / 2;r = 50 >= r ? 50 : r;Paint paint = new Paint();paint.setColor(Color.BLUE);canvas.drawCircle(x1, y1, r, paint);}天行健,君子以自强不息。勤奋是上天赐予我们的最大的财富,希望每一个人都能把握住自己的人生,用勤奋来获取多彩的人生。

Ⅸ android 图片放大缩小

网上有很多例子!

Ⅹ android webview 怎么放大缩小

Android:WebView如何设定支持缩放:需要对WebView和WebSettings做一下设定

webview.setVerticalScrollbarOverlay(true); //指定的垂直滚动条有叠加样式

WebSettings settings = webview.getSettings();
settings.setUseWideViewPort(true);//设定支持viewport
settings.setLoadWithOverviewMode(true);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);//设定支持缩放

html界面meta标签
<metaname="viewport"content="height= [pixel_value| "device-height"] ,width= [pixel_value| "device-width"] ,initial-scale=float_value,//初始缩放minimum-scale=float_value,//最小maximum-scale=float_value,//最大user-scalable= ["yes" | "no"]//是否允许用户对页面缩放 "/>

例如:<meta name="viewport" content="width=device-width,user-scalable=yes initial-scale=1.0, maximum-scale=2.0">-->设定支持缩放,最大两倍缩放

热点内容
安卓手机怎么注册苹果云 发布:2024-11-15 01:05:00 浏览:407
数据库设计模板 发布:2024-11-15 00:47:25 浏览:825
编程的悟性 发布:2024-11-15 00:47:24 浏览:733
主流可编译语言 发布:2024-11-15 00:42:23 浏览:729
excel缓存清除 发布:2024-11-15 00:39:53 浏览:486
机械键盘可编程 发布:2024-11-15 00:39:09 浏览:912
php判断字符开头 发布:2024-11-15 00:35:33 浏览:507
网易苹果游戏怎么转移到安卓 发布:2024-11-15 00:07:52 浏览:270
win7php环境搭建 发布:2024-11-15 00:06:55 浏览:17
erpjava 发布:2024-11-14 23:52:23 浏览:253