android如何在图像上设置按钮
我想在image()上设置一个按钮。我想这个按钮是固定在图像(地图)。所以我可以滚动/缩放,这个按钮应该固定在它的位置上。我尝试使用绝对布局(不推荐使用)和相对布局。没有一个成功android如何在图像上设置按钮,android,button,scroll,zooming,Android,Button,Scroll,Zooming,我想在image()上设置一个按钮。我想这个按钮是固定在图像(地图)。所以我可以滚动/缩放,这个按钮应该固定在它的位置上。我尝试使用绝对布局(不推荐使用)和相对布局。没有一个成功 // // DecimalFormat rounds to 2 decimal places. // df = new DecimalFormat("#.##"); scrollPositionTextView = (TextView) findViewById(R.id.scr
//
// DecimalFormat rounds to 2 decimal places.
//
df = new DecimalFormat("#.##");
scrollPositionTextView = (TextView) findViewById(R.id.scroll_position);
zoomedRectTextView = (TextView) findViewById(R.id.zoomed_rect);
currentZoomTextView = (TextView) findViewById(R.id.current_zoom);
image = (TouchImageView) findViewById(R.id.image);
//
// Set the OnTouchImageViewListener which updates edit texts
// with zoom and scroll diagnostics.
//
image.setOnTouchImageViewListener(new OnTouchImageViewListener() {
@Override
public void onMove() {
PointF point = image.getScrollPosition();
RectF rect = image.getZoomedRect();
float currentZoom = image.getCurrentZoom();
boolean isZoomed = image.isZoomed();
scrollPositionTextView.setText("x: " + df.format(point.x) + " y: " + df.format(point.y));
zoomedRectTextView.setText("left: " + df.format(rect.left) + " top: " + df.format(rect.top)
+ "\nright: " + df.format(rect.right) + " bottom: " + df.format(rect.bottom));
currentZoomTextView.setText("getCurrentZoom(): " + currentZoom + " isZoomed(): " + isZoomed);
}
});
你能给我一个建议吗?或者至少是一个参考阅读。我想做一些类似的东西,比如在沉降物掩体或部落冲突中(在那里你可以滚动并看到你的基地)。你可以使用Framelayout在图像顶部显示按钮,并使用view.offsetLeftAndRight方法更改按钮位置 e、 g
intlastx;
整形术;
无效设置按钮位置(整数x,整数y){
按钮。offsetLeftAndRight(x-lastX);
按钮。偏置和底部(y-拉sty);
lastX=x;
lastY=y;
}
我有类似的疑问,你找到解决办法了吗?那么请分享!!
int lastX;
int lastY;
void setButtonPosition(int x, int y) {
button.offsetLeftAndRight(x - lastX);
button.offsetTopAndBottom(y - lastY);
lastX = x;
lastY = y;
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|top"
android:text="Button" />
</FrameLayout>