Android Zoom Gallery 帮助
我真的需要帮助。 我有一个漫画书类型的独立应用程序。使用 onfling 手势来回翻转图像 然而,我迫切需要能够缩放每个图像/面板。 这是一个扩展画廊: 请帮助我向此代码添加缩放功能! 谢谢 请不要让我参考 stackoverflow 上已经发布的内容,我已经阅读了所有内容,但到目前为止它对我没有帮助......
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mygallery gallery = (mygallery) findViewById(R.id.thisgallery);
gallery.setAdapter(new AddImgAdp(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(main.this, "Page " + position, Toast.LENGTH_SHORT).show();
}
});
}
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
private Integer[] Imgid = {
R.drawable.s1,
R.drawable.s1a,
R.drawable.s1b,
R.drawable.s1b1,
R.drawable.s1b2,
R.drawable.s1b3,
R.drawable.s1c,
R.drawable.s1s,
R.drawable.s2,
R.drawable.s3,
R.drawable.s4,
R.drawable.s5,
R.drawable.s6,
R.drawable.s7,
R.drawable.s8,
R.drawable.s9,
R.drawable.s10,
R.drawable.s11,
R.drawable.s12,
R.drawable.s13,
R.drawable.s14,
R.drawable.s15,
R.drawable.s16,
R.drawable.s17,
R.drawable.s18,
R.drawable.s19,
R.drawable.s20,
R.drawable.s21,
R.drawable.s22,
R.drawable.s23,
R.drawable.s24,
R.drawable.s25,
R.drawable.s26,
R.drawable.s27,
R.drawable.s28,
R.drawable.s29,
R.drawable.s30,
R.drawable.s31,
R.drawable.s32,
R.drawable.s33,
R.drawable.s34,
R.drawable.s35,
R.drawable.s36,
R.drawable.s37,
R.drawable.s38,
R.drawable.s39,
R.drawable.s40,
R.drawable.s41,
R.drawable.s42,
R.drawable.s43,
R.drawable.s44,
R.drawable.s45,
R.drawable.s46,
R.drawable.s47,
R.drawable.s48,
R.drawable.s49,
R.drawable.s50,
R.drawable.s51,
R.drawable.s52,
R.drawable.s53,
R.drawable.s54,
R.drawable.s55,
R.drawable.s56,
R.drawable.s57,
R.drawable.s58,
R.drawable.s59,
R.drawable.s60,
R.drawable.s61,
R.drawable.s62,
R.drawable.s63,
R.drawable.s64,
R.drawable.s65,
R.drawable.s66,
R.drawable.s67,
R.drawable.s68,
R.drawable.s69,
R.drawable.s70,
R.drawable.s71,
R.drawable.s72,
R.drawable.s73,
R.drawable.s74,
R.drawable.s75,
R.drawable.s76,
R.drawable.s77,
R.drawable.s78,
R.drawable.s79,
R.drawable.s80,
R.drawable.s81,
R.drawable.s82,
R.drawable.s83,
R.drawable.s84,
R.drawable.s85,
R.drawable.s86,
R.drawable.s87,
R.drawable.s88,
R.drawable.s89,
R.drawable.s90,
R.drawable.s91,
R.drawable.s92,
R.drawable.s93,
R.drawable.s94,
R.drawable.s95,
R.drawable.s96,
R.drawable.s97,
R.drawable.s98,
R.drawable.s99,
R.drawable.s100,
R.drawable.s101,
R.drawable.s102,
R.drawable.s103,
R.drawable.s104,
R.drawable.s105,
R.drawable.s106,
R.drawable.s107,
R.drawable.s108,
R.drawable.s109,
R.drawable.s110,
R.drawable.s111,
R.drawable.s112,
R.drawable.s113,
R.drawable.s114,
R.drawable.s115,
R.drawable.s116,
R.drawable.s117,
R.drawable.s118,
R.drawable.s119,
R.drawable.s120,
R.drawable.s121,
R.drawable.s122,
R.drawable.s123,
R.drawable.s124,
R.drawable.s125,
R.drawable.s126,
R.drawable.s127,
R.drawable.s128,
R.drawable.s129,
R.drawable.s130,
R.drawable.s131,
R.drawable.s132,
R.drawable.s133,
R.drawable.s134,
R.drawable.s135,
R.drawable.s136,
R.drawable.s137,
R.drawable.s138,
R.drawable.s139,
R.drawable.s140,
R.drawable.s141,
R.drawable.s142,
R.drawable.s143,
R.drawable.s144,
R.drawable.s145,
R.drawable.s146,
R.drawable.s147,
R.drawable.s148};
public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.Gallery1);
GalItemBg = typArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
typArray.recycle();
}
public int getCount() {
return Imgid.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgView = new ImageView(cont);
imgView.setImageResource(Imgid[position]);
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(0x0106000d);
imgView.setLayoutParams(new mygallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return imgView;
}
}
}
以及 onfling 覆盖:
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;
public class mygallery extends Gallery {
public mygallery(Context ctx, AttributeSet attrSet) {
super(ctx, attrSet);
// TODO Auto-generated constructor stub
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){
return e2.getX() > e1.getX();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){
int kEvent;
if(isScrollingLeft(e1, e2)){ //Check if scrolling left
kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
}
else{ //Otherwise scrolling right
kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
}
onKeyDown(kEvent, null);
return true;
}
}
I really need help please.
I have a comic book type standalone app. The images are flipped using onfling gesture to turn page back and forth
However, I desperately need the ability to zoom for each image/panel.
This is an extended gallery:
Please help me add zoom functionality to this code!
thank you
Please do not refer me to things already posted here on stackoverflow i have read all of it and it isn't helping me thus far...
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mygallery gallery = (mygallery) findViewById(R.id.thisgallery);
gallery.setAdapter(new AddImgAdp(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(main.this, "Page " + position, Toast.LENGTH_SHORT).show();
}
});
}
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
private Integer[] Imgid = {
R.drawable.s1,
R.drawable.s1a,
R.drawable.s1b,
R.drawable.s1b1,
R.drawable.s1b2,
R.drawable.s1b3,
R.drawable.s1c,
R.drawable.s1s,
R.drawable.s2,
R.drawable.s3,
R.drawable.s4,
R.drawable.s5,
R.drawable.s6,
R.drawable.s7,
R.drawable.s8,
R.drawable.s9,
R.drawable.s10,
R.drawable.s11,
R.drawable.s12,
R.drawable.s13,
R.drawable.s14,
R.drawable.s15,
R.drawable.s16,
R.drawable.s17,
R.drawable.s18,
R.drawable.s19,
R.drawable.s20,
R.drawable.s21,
R.drawable.s22,
R.drawable.s23,
R.drawable.s24,
R.drawable.s25,
R.drawable.s26,
R.drawable.s27,
R.drawable.s28,
R.drawable.s29,
R.drawable.s30,
R.drawable.s31,
R.drawable.s32,
R.drawable.s33,
R.drawable.s34,
R.drawable.s35,
R.drawable.s36,
R.drawable.s37,
R.drawable.s38,
R.drawable.s39,
R.drawable.s40,
R.drawable.s41,
R.drawable.s42,
R.drawable.s43,
R.drawable.s44,
R.drawable.s45,
R.drawable.s46,
R.drawable.s47,
R.drawable.s48,
R.drawable.s49,
R.drawable.s50,
R.drawable.s51,
R.drawable.s52,
R.drawable.s53,
R.drawable.s54,
R.drawable.s55,
R.drawable.s56,
R.drawable.s57,
R.drawable.s58,
R.drawable.s59,
R.drawable.s60,
R.drawable.s61,
R.drawable.s62,
R.drawable.s63,
R.drawable.s64,
R.drawable.s65,
R.drawable.s66,
R.drawable.s67,
R.drawable.s68,
R.drawable.s69,
R.drawable.s70,
R.drawable.s71,
R.drawable.s72,
R.drawable.s73,
R.drawable.s74,
R.drawable.s75,
R.drawable.s76,
R.drawable.s77,
R.drawable.s78,
R.drawable.s79,
R.drawable.s80,
R.drawable.s81,
R.drawable.s82,
R.drawable.s83,
R.drawable.s84,
R.drawable.s85,
R.drawable.s86,
R.drawable.s87,
R.drawable.s88,
R.drawable.s89,
R.drawable.s90,
R.drawable.s91,
R.drawable.s92,
R.drawable.s93,
R.drawable.s94,
R.drawable.s95,
R.drawable.s96,
R.drawable.s97,
R.drawable.s98,
R.drawable.s99,
R.drawable.s100,
R.drawable.s101,
R.drawable.s102,
R.drawable.s103,
R.drawable.s104,
R.drawable.s105,
R.drawable.s106,
R.drawable.s107,
R.drawable.s108,
R.drawable.s109,
R.drawable.s110,
R.drawable.s111,
R.drawable.s112,
R.drawable.s113,
R.drawable.s114,
R.drawable.s115,
R.drawable.s116,
R.drawable.s117,
R.drawable.s118,
R.drawable.s119,
R.drawable.s120,
R.drawable.s121,
R.drawable.s122,
R.drawable.s123,
R.drawable.s124,
R.drawable.s125,
R.drawable.s126,
R.drawable.s127,
R.drawable.s128,
R.drawable.s129,
R.drawable.s130,
R.drawable.s131,
R.drawable.s132,
R.drawable.s133,
R.drawable.s134,
R.drawable.s135,
R.drawable.s136,
R.drawable.s137,
R.drawable.s138,
R.drawable.s139,
R.drawable.s140,
R.drawable.s141,
R.drawable.s142,
R.drawable.s143,
R.drawable.s144,
R.drawable.s145,
R.drawable.s146,
R.drawable.s147,
R.drawable.s148};
public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.Gallery1);
GalItemBg = typArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
typArray.recycle();
}
public int getCount() {
return Imgid.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgView = new ImageView(cont);
imgView.setImageResource(Imgid[position]);
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(0x0106000d);
imgView.setLayoutParams(new mygallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return imgView;
}
}
}
and the onfling override:
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Gallery;
public class mygallery extends Gallery {
public mygallery(Context ctx, AttributeSet attrSet) {
super(ctx, attrSet);
// TODO Auto-generated constructor stub
}
private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){
return e2.getX() > e1.getX();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){
int kEvent;
if(isScrollingLeft(e1, e2)){ //Check if scrolling left
kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
}
else{ //Otherwise scrolling right
kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
}
onKeyDown(kEvent, null);
return true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用android的ScaleAnimation类来实现缩放效果。但问题是,动画实际上不会改变它所应用的视图的大小/位置,这是一个很大的问题,因为应用动画的视图的点击区域将始终保持不变,并且很快。然而,没有其他方法可以实现缩放效果 AFAIK。(至少在 3.0 之前的 android 版本中)。
You can use the android ScaleAnimation class to achieve the zoom effect. The thing is, though, that the animation won't actually change the size/position of the view that it's applied on and that's quite a problem since the hit are of the view you're applying the animation on will always remain the same and so on. However there's no other way to achieve zoom effect AFAIK.(at least in versions of android prior to 3.0).