我真的需要帮助。 我有一个漫画类型的独立应用程序。使用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;
}
}
答案 0 :(得分:0)
您可以使用android ScaleAnimation类来实现缩放效果。但事实是,动画实际上不会改变它所应用的视图的大小/位置,这是一个非常大的问题,因为你正在应用动画的视图的命中将始终保持相同,等等。然而,没有其他方法可以实现缩放效果AFAIK。(至少在3.0之前的Android版本中)。