我需要一个滚动视图,我可以在其中以编程方式和单击添加图像和按钮的数量,通过在水平和垂直方向上捏缩放并平滑滚动。这是我需要的视频。我尝试过在 ScrollView 中使用水平滚动视图。我可以流畅地滚动。我可以单击添加项目。我现在不能缩放。这是示例代码:
public void setUpNoticeBoard(){
canvasLayout = (FrameLayout) findViewById(R.id.frameLayout);
canvasLayout.removeAllViews();
FrameLayout.LayoutParams paramsImage = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
final ImageView noticeBoard = new ImageView(this);
noticeBoard.setLayoutParams(paramsImage);
noticeBoard.setAdjustViewBounds(true);
noticeBoard.setImageDrawable(getResources().getDrawable(R.drawable.noticeboard));
noticeBoard.setScaleType(ImageView.ScaleType.CENTER_CROP);
canvasLayout.addView(noticeBoard);
float xx = noticeBoard.getWidth();
float yy = noticeBoard.getHeight();
System.out.println("noticeBoard Width:" + xx + "And Height:" + yy);
for (int i = 0; i < 50; i++) {
int x= (int)Math.ceil(Math.random()*3000);
int y= (int)Math.ceil(Math.random()*2000);
FrameLayout.LayoutParams paramsNotice = new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsNotice.setMargins(x, y, 0, 0);
final ImageView notice = new ImageView(this);
notice.setLayoutParams(paramsNotice);
Resources res = getResources();
String imageName = "pin" + (int)Math.ceil(Math.random()*8);
int resourceId = res.getIdentifier(imageName, "drawable", getPackageName() );
notice.setTag(imageName);
notice.setImageResource(resourceId);
canvasLayout.addView(notice);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float curX, curY;
newPin.setVisibility(View.INVISIBLE);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mx = event.getX();
my = event.getY();
break;
case MotionEvent.ACTION_MOVE:
curX = event.getX();
curY = event.getY();
vScroll.scrollBy((int) (mx - curX), (int) (my - curY));
hScroll.scrollBy((int) (mx - curX), (int) (my - curY));
mx = curX;
my = curY;
break;
case MotionEvent.ACTION_UP:
curX = event.getX();
curY = event.getY();
vScroll.scrollBy((int) (mx - curX), (int) (my - curY));
hScroll.scrollBy((int) (mx - curX), (int) (my - curY));
break;
}
return gestureScanner.onTouchEvent(event);
}
public boolean onSingleTapUp(MotionEvent e) {
int x = (int) e.getX();
int y = (int) e.getY();
FrameLayout.LayoutParams paramsNewPin = new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
paramsNewPin.setMargins(x + hScroll.getScrollX() - 98, y + vScroll.getScrollY() - 250, 0, 0);
final ImageView newPin = new ImageView(this);
newPin.setLayoutParams(paramsNewPin);
newPin.setImageResource(R.drawable.pin5);
canvasLayout.addView(newPin);
return true;
}
现在我需要 1 件事放大夹点(布局上的全部内容将被缩放)谢谢。