先給大家展示下效果圖,如果大家感覺(jué)不錯(cuò),請(qǐng)參考實(shí)現(xiàn)代碼
創(chuàng)新互聯(lián)建站專(zhuān)注于下花園網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供下花園營(yíng)銷(xiāo)型網(wǎng)站建設(shè),下花園網(wǎng)站制作、下花園網(wǎng)頁(yè)設(shè)計(jì)、下花園網(wǎng)站官網(wǎng)定制、微信平臺(tái)小程序開(kāi)發(fā)服務(wù),打造下花園網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供下花園網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。效果圖如下所示:
代碼如下所示:
public class MainActivity extends Activity { View view; public static final int DRAG = 1; public static final int SCALE = 2; int mode = 1; int height = 10, width = 10; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); view = findViewById(R.id.view); } float length = 1; // 重寫(xiě) @Override public boolean onTouchEvent(MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); // 多指觸控 switch (event.getAction() & event.getActionMasked()) { case MotionEvent.ACTION_DOWN: mode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: Log.e("TAG", "多指移動(dòng)"); mode = SCALE; // 兩個(gè)手指開(kāi)始的長(zhǎng)度是多少呢? length = calc(event); break; case MotionEvent.ACTION_UP: length = 1; break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { // 1. 單個(gè)手指 FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( width, height); params.setMargins(x, y, 0, 0); view.setLayoutParams(params); } else { // 2. 兩個(gè)手指 float beilv = calc(event) / length; width = (int) (view.getWidth() * beilv); height = (int) (view.getHeight() * beilv); Log.e("TAG", beilv + " " + width + " " + height); FrameLayout.LayoutParams params = (LayoutParams) view .getLayoutParams(); params.width = width; params.height = height; view.setLayoutParams(params); } break; } return true; } // 類(lèi) Ponint public float calc(MotionEvent event) { float x1 = event.getX(); float y1 = event.getY(); float x2 = event.getX(1); float y2 = event.getY(1); return (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } }