小编w1c*_*d64的帖子

android imageView:设置拖动和捏缩放参数

我目前正在为Android(我的第一个应用程序)开发一个应用程序,它可以让用户看到地铁地图,并能够捏缩放和拖动.

我目前正在修改Hello Android,3rd Edition中的代码,并进行了缩放缩放和拖动工作.我正在使用Matrix作为我的布局比例.

但是我现在有3个问题:

  1. 我尝试了很多东西来限制拖动参数,但我似乎无法阻止它被拖离父视图(并且实际上可以从视图中消失).我已经尝试在XML文件中设置布局参数,但它不起作用.

  2. 我可以捏缩放,但我又遇到了麻烦,限制了变焦量.我正在尝试设置max_zoom和min_zoom以限制缩放值(我将在之后发布我的代码)

  3. 我也很难尝试在我的图像上映射坐标,以便人们可以点击某些部分(这一点的全部意义是让用户点击地图上的一个工作站并查看有关它的信息)

我有一种感觉我遇到了麻烦,因为我正在使用矩阵比例.

这是我目前的代码:

Touch.java

package org.example.touch;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.GridView;
import android.widget.ImageView;

public class Touch extends Activity implements OnTouchListener {
private static final String TAG = "Touch";

private static final float MIN_ZOOM = 1.0f;
private static final float MAX_ZOOM = 5.0f;

// These matrices will be used to move and zoom image
Matrix matrix = …
Run Code Online (Sandbox Code Playgroud)

android drag-and-drop zoom pinch imageview

29
推荐指数
6
解决办法
6万
查看次数

android - 动态改变imageview的位置

我目前正在使用矩阵方法为图像实现拖动和缩放缩放(图像A)

现在我希望图像A的一部分可以点击,所以我将另一个图像视图(图像B)放在图像A上,并在xml文件中为它设置layout_margins.

我的问题是......有没有办法动态改变我的layout_margins,因为我正在缩放我的图像以进行拖拽缩放?

我想更简单的问题是......我如何为imageview动态设置layout_margins?

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

   <ImageView android:id="@+id/imageView"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:src="@drawable/map"
     android:scaleType="matrix" />

    <ImageView
       android:id="@+id/dundas_station"
       android:layout_width="75px"
       android:layout_height="75px"
       android:layout_marginTop="337px"
   android:layout_marginLeft="373px"
       android:clickable="true"
       android:src="@drawable/google_maps_icon"
       android:scaleType="matrix"
       />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

谢谢!

layout android dynamic

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

drag-and-drop ×1

dynamic ×1

imageview ×1

layout ×1

pinch ×1

zoom ×1