我正在努力使我的部分形象可点击。在这种情况下,我有24个端口开关,我希望当用户单击端口时显示端口号。我已经做了缩放,并试图在图像上插入矩形,但我在中还是新手,所以我不太确定如何完成任务。
下面是我创建矩形并放到图片上的代码:(我的想法是,我有一个类矩形来保存端口号和一些文本,这样我就可以检索它们)
public class MainActivity extends Activity{
ImageView DrawingImage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DrawingImage = (ImageView) this.findViewById(R.id.image);
Bitmap bitmap2 = Bitmap.createBitmap((int) getWindowManager()
.getDefaultDisplay().getWidth(), (int) getWindowManager()
.getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap2);
DrawingImage.setImageBitmap(bitmap2);
// Draw Rectangle
Paint paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.FILL);
float left = 20;
float top = 20;
float right = 50;
float bottom = 100;
canvas.drawRect(left, top, right, bottom, paint);
Zoom image = (Zoom) findViewById(R.id.image);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test);
image.setImageBitmap(bitmap);
int posX=(int)image.getX();
int posY=(int)image.getY();
double height=image.getHeight();
double width=image.getWidth();
}
}但是当我运行应用程序时,我看不到矩形。即使我在矩形之前声明图片,我也只能看到矩形。
有什么建议吗?
任何帮助都将不胜感激。
提前谢谢你!
向你问好,迪米蒂尔·乔治耶夫
发布于 2013-09-19 06:44:47
xml布局:
<FrameLayout 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/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>onCreate方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView DrawingImage = (ImageView) this.findViewById(R.id.imageView2);
Bitmap bitmap2 = Bitmap.createBitmap((int) getWindowManager()
.getDefaultDisplay().getWidth(), (int) getWindowManager()
.getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap2);
DrawingImage.setImageBitmap(bitmap2);
// Draw Rectangle
Paint paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.FILL);
float left = 20;
float top = 20;
float right = 50;
float bottom = 100;
canvas.drawRect(left, top, right, bottom, paint);
ImageView image = (ImageView) findViewById(R.id.imageView1);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
image.setImageBitmap(bitmap);
int posX=(int)image.getX();
int posY=(int)image.getY();
double height=image.getHeight();
double width=image.getWidth();
}现在不是你先画什么的问题。是关于xml布局的。先放什么。当然,您可能希望使用图像视图的高度和宽度属性来实现您真正想要的目标。但这起作用了我测试过了。
发布于 2013-09-18 12:55:00
这不管用。就像你那样做。
在您的设计中必须有两个图像视图。
使用framelayout并将两个图像视图放入其中。
把画布放在其中一个,然后画。
并为另一个设置图像。
由于设置了第一个位图,它将无法工作:
DrawingImage.setImageBitmap(bitmap2);然后你更换它:
image.setImageBitmap(bitmap);您有相同的图像布局:
R.id.imagehttps://stackoverflow.com/questions/18871491
复制相似问题