4

我有应用程序,它的一项活动是无限厨房,图像存储在 res 可绘制文件夹中,

我试图对图像进行双标签和双指缩放,

我搜索谷歌没有任何与无限画廊缩放效果相关的例子,

任何建议将被认真考虑 。

DayGallery.java:

 @SuppressWarnings("deprecation")
public class DayGallery extends Activity {
TextView tv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);  
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
// Set the layout to use
setContentView(R.layout.main);
if (customTitleSupported) { 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
     tv = (TextView) findViewById(R.id.title_tv1); 
     tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
     }           
InfiniteGallery galleryOne = (InfiniteGallery) findViewById(R.id.galleryOne);
galleryOne.setAdapter(initializeImages()); 
galleryOne.setSelection(galleryOne.getCount()/2);  
}  

private InfiniteGalleryAdapter initializeImages() {
InfiniteGalleryAdapter galleryAdapter = null;

String day = getIntent().getStringExtra("dayname");

if(day.equalsIgnoreCase("Day1")){
    int[] tempimages = { R.drawable.day_one_1, R.drawable.day_one_2,R.drawable.day_one_3, 
            R.drawable.day_one_4, R.drawable.day_one_5,R.drawable.day_one_6,R.drawable.day_one_7,       
            R.drawable.day_one_8, R.drawable.day_one_9,R.drawable.day_one_10,R.drawable.day_one_11,
            R.drawable.day_one_12
    };  
    String[] name = { "00:35","00:35","00:35","1:07","2:00","2:01","2:09",
                      "2:12","2:15","6:13","6:13","6:13"
    };  
    tv.setText("Day one pictures");
    galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); 
    }       
else if(day.equalsIgnoreCase("Day2")){
    int[] tempimages = { R.drawable.day_two_1, R.drawable.day_two_2,R.drawable.day_two_3, 
            R.drawable.day_two_4, R.drawable.day_two_5,R.drawable.day_two_6,R.drawable.day_two_7,
            R.drawable.day_two_8, R.drawable.day_two_9,R.drawable.day_two_10,R.drawable.day_two_11,
            R.drawable.day_two_12
    };  
    String[] name = { "12:04","12:04", "12:04","12:05","12:06", "12:07",
                      "12:07","12:07","12:08","12:10","12:10","12:10"
    };  
    tv.setText("Day two pictures"); 
    galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); 
    }

// AND THE SAME FOR REST OF DAYS TILL Day10//

return galleryAdapter; 
}
}

class InfiniteGalleryAdapter extends BaseAdapter { 
private Context mContext;
private int[] images;   
private String[] name;
public InfiniteGalleryAdapter(Context c, int[] imageIds,String[] names) { 
this.mContext = c; 
images = imageIds;
name=names;
inflater = (LayoutInflater)mContext.getSystemService ( Context.LAYOUT_INFLATER_SERVICE); 
} 
public int getCount() { 
return Integer.MAX_VALUE; 
} 
public Object getItem(int position) { 
return position; 
} 
public long getItemId(int position) { 
return position; 
} 
private LayoutInflater inflater=null; 

public class ViewHolder{ 
public TextView text; 
public ImageView image; 
} 

public View getView(int position, View convertView, ViewGroup parent) { 
ImageView i = getImageView(); 

int itemPos = (position % images.length); 

try { i.setImageResource(images[itemPos]); ((BitmapDrawable) i.getDrawable()).setAntiAlias(true); 
} 
catch (OutOfMemoryError e) { Log.e("InfiniteGalleryAdapter", "Out of memory creating imageview. Using empty view.", e); 
} 
View vi=convertView; 
ViewHolder holder; 
if(convertView==null){ 
    vi = inflater.inflate(R.layout.gallery_items, null); 
    holder=new ViewHolder(); 
    holder.text=(TextView)vi.findViewById(R.id.textView1); 
    holder.image=(ImageView)vi.findViewById(R.id.image); 
    vi.setTag(holder); 
    } 
else holder=(ViewHolder)vi.getTag(); 
holder.text.setText(name[itemPos]); 

final int stub_id=images[itemPos]; 
holder.image.setImageResource(stub_id); 

return vi; 
} 

private ImageView getImageView() { 

ImageView i = new ImageView(mContext); 

return i; 
} 
}

 @SuppressWarnings("deprecation")
class InfiniteGallery extends Gallery {

public InfiniteGallery(Context context) {
super(context);
init(); 
}

public InfiniteGallery(Context context, AttributeSet attrs) {
super(context, attrs);
init(); 
}

public InfiniteGallery(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(); 
}

private void init(){
// These are just to make it look pretty
setSpacing(25);
setHorizontalFadingEdgeEnabled(false); 
}
}

主要的.xml

<?xml version="1.0" encoding="utf-8" ?> 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" 
   android:background="#FFDAB9">
 <com.test.demo.InfiniteGallery 
   android:id="@+id/galleryOne" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" /> 
</LinearLayout>

更新:

根据 Yoann Hercouet 的回答,我替换了以下代码:

 private ImageView getImageView() { 
  ImageView i = new ImageView(mContext); 
  return i; 
 } 
 }

使用以下代码:

 private GestureImageView getImageView() {   
  GestureImageView i = new GestureImageView(mContext); 
   return i; 
  } 
  }

还要调整getview,所以最后我的课如下:

 @SuppressWarnings("deprecation")
public class DayGallery extends Activity {
 TextView tv;

    /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
    WindowManager.LayoutParams.FLAG_FULLSCREEN);  
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
 Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 

 setContentView(R.layout.main);
 if (customTitleSupported) { 
   getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
     tv = (TextView) findViewById(R.id.title_tv1); 
     tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
    } 

 InfiniteGallery galleryOne = (InfiniteGallery) findViewById(R.id.galleryOne);
  galleryOne.setAdapter(initializeImages()); 
  galleryOne.setSelection(galleryOne.getCount()/2);  
  }  

 private InfiniteGalleryAdapter initializeImages() {
  InfiniteGalleryAdapter galleryAdapter = null;

   String day = getIntent().getStringExtra("dayname");

  if(day.equalsIgnoreCase("Day1")){
   int[] tempimages = { R.drawable.day_one_1, R.drawable.day_one_2,R.drawable.day_one_3, 
        R.drawable.day_one_4, R.drawable.day_one_5,R.drawable.day_one_6,R.drawable.day_one_7,       
        R.drawable.day_one_8, R.drawable.day_one_9,R.drawable.day_one_10,R.drawable.day_one_11,
        R.drawable.day_one_12
};  
String[] name = { "00:35","00:35","00:35","1:07","2:00","2:01","2:09",
                  "2:12","2:15","6:13","6:13","6:13"
};  
tv.setText("Day one pictures");
galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); 
}       
else if(day.equalsIgnoreCase("Day2")){
   int[] tempimages = { R.drawable.day_two_1, R.drawable.day_two_2,R.drawable.day_two_3, 
        R.drawable.day_two_4, R.drawable.day_two_5,R.drawable.day_two_6,R.drawable.day_two_7,
        R.drawable.day_two_8, R.drawable.day_two_9,R.drawable.day_two_10,R.drawable.day_two_11,
        R.drawable.day_two_12
};  
String[] name = { "12:04","12:04", "12:04","12:05","12:06", "12:07",
                  "12:07","12:07","12:08","12:10","12:10","12:10"
};  
tv.setText("Day two pictures"); 
galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); 
}

        // AND THE SAME FOR REST OF DAYS TILL Day10//

return galleryAdapter; 
 }
 }

 class InfiniteGalleryAdapter extends BaseAdapter { 
private Context mContext;
private int[] images;   
private String[] name;
public InfiniteGalleryAdapter(Context c, int[] imageIds,String[] names) { 
    this.mContext = c; 
    images = imageIds;
    name=names;
    inflater = (LayoutInflater)mContext.getSystemService ( Context.LAYOUT_INFLATER_SERVICE); 
    }

public int getCount() { 
    return Integer.MAX_VALUE; 
    } 

public Object getItem(int position) { 
    return position; 
    } 

public long getItemId(int position) { 
    return position; 
    } 

private LayoutInflater inflater=null; 

public class ViewHolder{ 
    public TextView text; 
    public ImageView image; 
    } 
public View getView(int position, View convertView, ViewGroup parent) { 
    GestureImageView i = getImageView(); 
    int itemPos = (position % images.length); 
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);//addition

    try { 
        i.setImageResource(images[itemPos]); 
        ((BitmapDrawable) i.getDrawable()).setAntiAlias(true);
        i.setLayoutParams(params); //addition
    } 
    catch (OutOfMemoryError e) { 
        Log.e("InfiniteGalleryAdapter", "Out of memory creating   imageview. Using empty view.", e); 
    } 
    View vi=convertView; 
    ViewHolder holder; 
    if(convertView==null){ 
        vi = inflater.inflate(R.layout.gallery_items, null); 
        holder=new ViewHolder(); 
        holder.text=(TextView)vi.findViewById(R.id.textView1); 
        holder.image=(ImageView)vi.findViewById(R.id.image); 
        vi.setTag(holder); 
        } 

    else holder=(ViewHolder)vi.getTag(); 
    holder.text.setText(name[itemPos]); 

    final int stub_id=images[itemPos]; 
    holder.image.setImageResource(stub_id); 

    return vi; 
    } 

 private GestureImageView getImageView() {   
   GestureImageView i = new GestureImageView(mContext); 
    return i; 
   } 

  @SuppressWarnings("deprecation")
  class InfiniteGallery extends Gallery {

public InfiniteGallery(Context context) {
    super(context);
    init(); 
    }

public InfiniteGallery(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(); 
    }

public InfiniteGallery(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(); 
    }

private void init(){
    // These are just to make it look pretty
    setSpacing(25);
    setHorizontalFadingEdgeEnabled(false); 
}
}   
}

如果我将修改后的类与下面的原始 main.xmla 一起使用:

<?xml version="1.0" encoding="utf-8" ?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" 
  android:background="#FFDAB9">
<com.test.demo.InfiniteGallery
  android:id="@+id/galleryOne" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" /> 
</LinearLayout>

它使用以下 logcat 强制关闭:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.demo/com.ttest.demo.DayGallery}: android.view.InflateException: Binary XML file line #7: Error inflating class com.test.demo.InfiniteGallery
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
   Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.tsn.dr.InfiniteGallery
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:216)
at android.app.Activity.setContentView(Activity.java:1660)
at com.test.demo.DayGallery.onCreate(DayGallery.java:35)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
  Caused by: java.lang.ClassNotFoundException: com.test.demo.InfiniteGallery in loader dalvik.system.PathClassLoader[/data/app/com.test.demo-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.view.LayoutInflater.createView(LayoutInflater.java:471)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
... 20 more

如果我将修改后的类与修改后的 main.xml 一起使用,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:gesture-image="http://schemas.polites.com/android"
  android:id="@+id/layout"
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" 
  android:background="#FFDAB9">
<com.test.demo.InfiniteGallery 
   android:id="@+id/galleryOne" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" /> 

 <com.polites.android.GestureImageView
   android:id="@+id/image"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" 
   gesture-image:min-scale="0.75"
  gesture-image:max-scale="10.0"
 />

它还使用以下 logcat 强制关闭:

  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.demo/com.test.demo.DayGallery}: android.view.InflateException: Binary XML file line #9: Error inflating class com.test.demo.InfiniteGallery
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.test.demo.InfiniteGallery
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:216)
at android.app.Activity.setContentView(Activity.java:1660)
at com.test.demo.DayGallery.onCreate(DayGallery.java:35)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
  Caused by: java.lang.ClassNotFoundException: com.tsn.dr.InfiniteGallery in loader dalvik.system.PathClassLoader[/data/app/com.tsn.dr-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.view.LayoutInflater.createView(LayoutInflater.java:471)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
... 20 more

更新 2

在此处输入图像描述

4

5 回答 5

1

我在我的项目中使用PhotoView 。它类似于您现在尝试的 GestureImageView。

下面是 PhotoView 的使用示例:

<ProgressBar
    android:id="@+id/progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:indeterminate="true"
    android:visibility="gone" />

<RelativeLayout
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <uk.co.senab.photoview.PhotoView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/buttonsContainer"
        android:layout_centerInParent="true"
        android:layout_marginBottom="@dimen/offset_vertical"
        android:layout_marginLeft="@dimen/offset_horizontal"
        android:layout_marginRight="@dimen/offset_horizontal"
        android:layout_marginTop="@dimen/offset_vertical"
        tools:ignore="ContentDescription" />

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

        <Button
            android:id="@+id/makeAvatarButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/make_avatar" />

        <Button
            android:id="@+id/deleteButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/delete" />
    </LinearLayout>
</RelativeLayout>

在您的 Java 代码中,您可以像使用简单的 ImageView 一样使用它。这是我的代码(我使用UrlImageViewHelper异步加载图像):

protected void processData() {
    View view = getView();
    if (null != view) {
        View makeAvatarButton = view.findViewById(R.id.makeAvatarButton);
        String link = JSONUtils.getLink(jsonData, "url");
        ImageView image = (ImageView) view.findViewById(R.id.image);
        UrlImageViewHelper.setUrlDrawable(image, link);

        boolean avatar = jsonData.optBoolean("avatar", false);
        if (avatar) {
            makeAvatarButton.setVisibility(View.GONE);
        } else {
            makeAvatarButton.setVisibility(View.VISIBLE);
        }
    }
}

您在公共 View getView(int position, View convertView, ViewGroup parent)方法中的代码中有错误。您在第 96 行创建了一个 GestureImageView,但之后不再使用它。相反,您正在夸大gallery_items.xml的内容并返回它们。我猜gallery_items.xml只包含一个带有文本标签的图像,所以这是一个应该可以正常工作的示例:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<uk.co.senab.photoview.PhotoView
    android:id="@+id/thumbnail"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="100dp"
    android:padding="5dp"
    android:scaleType="fitXY"
    tools:ignore="ContentDescription" >
</uk.co.senab.photoview.PhotoView>

<TextView
    android:id="@+id/label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal" /></LinearLayout>

然后你可以将你的getView方法简化为:

public View getView(int position, View convertView, ViewGroup parent) {
    int itemPos = (position % images.length);
    View vi = convertView;
    ViewHolder holder;
    if (convertView == null) {
        vi = inflater.inflate(R.layout.gallery_items, null);
        holder = new ViewHolder();
        holder.text = (TextView) vi.findViewById(R.id.textView1);
        holder.image = (ImageView) vi.findViewById(R.id.image);
        vi.setTag(holder);
    } else {
        holder = (ViewHolder) vi.getTag();
    }
    holder.text.setText(name[itemPos]);

    final int stub_id = images[itemPos];
    holder.image.setImageResource(stub_id);

    return vi;
}

如果您在运行代码时遇到问题,我可以为您组装一个简单的画廊项目。:)

于 2013-08-26T12:48:17.540 回答
1

我在我的应用程序上使用以下库: https ://github.com/jasonpolites/gesture-imageview

该库提供您所要求的内容(双击和捏缩放)以及其他功能。

您可以通过编程方式设置图像:

GestureImageView view = new GestureImageView(this);
view.setImageResource(R.drawable.image);
view.setAdjustViewBounds(true);
view.setLayoutParams(params);

然后你只需要在你的布局中添加视图,在你的情况下,你的想法是向你提供这些视图,InfiniteGalleryAdapter但我没有找到关于这个库的太多信息。

这个类很容易设置,只需将它集成到您​​的项目中并按照链接中的示例进行操作即可。

编辑

必须在您的 中进行更改InfiniteGalleryAdapter,我认为您可以通过以下方式更改getImageView功能来尝试一下:

private GestureImageView getImageView() {   
    GestureImageView i = new GestureImageView(mContext); 

    return i; 
} 

您可能还需要修改try适配器的一部分以添加布局参数:

public View getView(int position, View convertView, ViewGroup parent) { 
GestureImageView i = getImageView(); 

int itemPos = (position % images.length); 
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);//addition

try { 
    i.setImageResource(images[itemPos]); 
    ((BitmapDrawable) i.getDrawable()).setAntiAlias(true);
    i.setLayoutParams(params); //addition
} 
catch (OutOfMemoryError e) { 
    Log.e("InfiniteGalleryAdapter", "Out of memory creating   imageview. Using empty view.", e); 
} 

对于 XML,该库所在的网站中有一个示例。在我们的例子中,GestureImageView 是以编程方式添加的,所以您似乎只需要通过添加以下行来修改一点 XML 文件xmlns:gesture-image="http://schemas.polites.com/android"

<?xml version="1.0" encoding="utf-8" ?> 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:gesture-image="http://schemas.polites.com/android"
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:orientation="vertical" 
   android:background="#FFDAB9">
<com.test.demo.InfiniteGallery 
   android:id="@+id/galleryOne" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" /> 
</LinearLayout>

编辑2

这是您可以尝试阻止滚动“燃烧”事件的方法,onTouch将类中的原始函数替换为GestureImageViewTouchListener下面的函数,我只是添加了对运动动作的检查:

@Override
    public boolean onTouch(View v, MotionEvent event) {

        if(event.getAction() != MotionEvent.ACTION_SCROLL){
            if(!inZoom) {

                if(!tapDetector.onTouchEvent(event)) {
                    if(event.getPointerCount() == 1 && flingDetector.onTouchEvent(event)) {
                        startFling();
                    }

                    if(event.getAction() == MotionEvent.ACTION_UP) {
                        handleUp();
                    }
                    else if(event.getAction() == MotionEvent.ACTION_DOWN) {
                        stopAnimations();

                        last.x = event.getX();
                        last.y = event.getY();

                        if(imageListener != null) {
                            imageListener.onTouch(last.x, last.y);
                        }

                        touched = true;
                    }
                    else if(event.getAction() == MotionEvent.ACTION_MOVE) {
                        if(event.getPointerCount() > 1) {
                            multiTouch = true;
                            if(initialDistance > 0) {

                                pinchVector.set(event);
                                pinchVector.calculateLength();

                                float distance = pinchVector.length;

                                if(initialDistance != distance) {

                                    float newScale = (distance / initialDistance) * lastScale;

                                    if(newScale <= maxScale) {
                                        scaleVector.length *= newScale;

                                        scaleVector.calculateEndPoint();

                                        scaleVector.length /= newScale;

                                        float newX = scaleVector.end.x;
                                        float newY = scaleVector.end.y;

                                        handleScale(newScale, newX, newY);
                                    }
                                }
                            }
                            else {
                                initialDistance = MathUtils.distance(event);

                                MathUtils.midpoint(event, midpoint);

                                scaleVector.setStart(midpoint);
                                scaleVector.setEnd(next);

                                scaleVector.calculateLength();
                                scaleVector.calculateAngle();

                                scaleVector.length /= lastScale;
                            }
                        }
                        else {
                            if(!touched) {
                                touched = true;
                                last.x = event.getX();
                                last.y = event.getY();
                                next.x = image.getImageX();
                                next.y = image.getImageY();
                            }
                            else if(!multiTouch) {
                                if(handleDrag(event.getX(), event.getY())) {
                                    image.redraw();
                                }
                            }
                        }
                    }
                }           
            }
            return true;
        } 
        else {
            return false;
        }
    }
于 2013-08-22T13:59:50.613 回答
1

您可以使用自定义 imagGallery 控件。检查此https://github.com/kilaka/ImageViewZoom 您可以将图像滑动为画廊视图并能够进行捏缩放。在这个例子中,你有一个适配器类..检查一下。

于 2013-08-14T10:15:48.103 回答
1

您可以使用我的Pinch 来缩放 Gallery项目。您可以从图库中选择任何图像,然后在onDoubleTap(MotionEvent e)打开的完整图像中进行缩放。您应该使用两个小部件类PinchZoomGalleryTouchImageView活动类PinchZoomActivity或将画廊功能添加到您的活动类中。

于 2013-08-20T16:56:08.207 回答
0

我认为您ClassNotFoundException是由于 android 运行时尝试实例化com.tsn.dr.InfiniteGallery您在活动中指定的 a :

<com.test.demo.InfiniteGallery 
android:id="@+id/galleryOne" 
android:layout_width="match_parent" 
android:layout_height="match_parent" /> 

但是 InfiniteGallery 类是私有的,在 DayGallery 内部:

public class DayGallery {
    ....
    @SuppressWarnings("deprecation")
    class InfiniteGallery extends Gallery {

将其公开并修复 .xml 中的包路径以匹配它的实际命名空间。(对不起c#术语,几个月没做android工作了)

于 2013-08-26T16:52:56.980 回答