gpt4 book ai didi

java - 无法放大巴士路线图

转载 作者:行者123 更新时间:2023-12-01 04:49:31 25 4
gpt4 key购买 nike

我有一张巴士路线图作为图像。使用缩放 Controller ,图像缩小但未放大请查看我的代码并让我知道要完成的更改才能使其正常工作。我正在 Gingerbread 上开发我的应用程序,即 API 10

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ZoomControls;

public class Busmaps extends Activity {

ImageView img;
ZoomControls zoom;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.busmaps);

img = (ImageView) findViewById(R.id.imageViewmaps1);
zoom = (ZoomControls) findViewById(R.id.zoomControls1);

zoom.setOnZoomInClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

int w = img.getWidth();
int h = img.getHeight();

RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(w + 50, h + 50);
params.addRule(RelativeLayout.CENTER_IN_PARENT);

img.setLayoutParams(params);
}
});

zoom.setOnZoomOutClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

int w = img.getWidth();
int h = img.getHeight();

RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(w - 50, h - 50);
params.addRule(RelativeLayout.CENTER_IN_PARENT);

img.setLayoutParams(params);
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bus_map_zoom, menu);
return true;
}
}

我的 xml 表示公交车路线图像:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:id="@+id/imageViewmaps1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/map" />

<ZoomControls
android:id="@+id/zoomControls1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>

</RelativeLayout>

我应该如何使我的缩放控件同时适用于放大和缩小。

最佳答案

请将您的 Zoom in 和 ZoomOut 监听器替换为以下内容:

zoom.setOnZoomInClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

float x = img.getScaleX();
float y = img.getScaleY();

img.setScaleX((float) (x+1));
img.setScaleY((float) (y+1));
}
});

zoom.setOnZoomOutClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub


float x = img.getScaleX();
float y = img.getScaleY();

img.setScaleX((float) (x-1));
img.setScaleY((float) (y-1));
}
});
}

替代选项是在内置缩放 Controller 的 Web View 中加载图像。

如下:

 String page = "<html><body><center><img src=\""+path to your image+"\"/></center></body></html>";
webView.loadDataWithBaseURL("fake",page, "text/html", "UTF-8","");

如果您不想使用内置的 Web View 缩放 Controller ,那么您只需放置自己的按钮并在 Web View 上应用放大和缩小,如下所示:

webView.setInitialScale(ZOOM_LEVEL);

关于java - 无法放大巴士路线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15215114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com