esmail3309
شنبه 04 مرداد 1393, 17:39 عصر
سلام دوستا ی گلم
یک کد گالری با این قابلیت که وقتی انگشت رو به چپ و راست میکشی عکس هم تغیر کنه :
package com.example.aksdoni;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.Toast;
import android.widget.ViewSwitcher.ViewFactory;
public class Activity_Menu_Teroll extends Activity{
int imgPos, imgPrePos;
ImageSwitcher iSwitch;
Animation slideInLeft, slideInRight;
Toast mToast;
int xDown, xUp;
int[] imgList = {
R.drawable.img1,
R.drawable.img2,
R.drawable.img3,
R.drawable.img4,
R.drawable.img5,
R.drawable.img6,
R.drawable.img7,
R.drawable.img8,
R.drawable.img9,
R.drawable.img10,
R.drawable.img11,
R.drawable.img12,
R.drawable.img13,
R.drawable.img14,
R.drawable.img15,
R.drawable.img16,
R.drawable.img17,
R.drawable.img18,
R.drawable.img19,
R.drawable.img20,
R.drawable.img21,
R.drawable.img22,
R.drawable.img23,
R.drawable.img24,
R.drawable.img25,
R.drawable.img26,
R.drawable.img27,
R.drawable.img28,
R.drawable.img29,
R.drawable.img30,
R.drawable.img31,
R.drawable.img32,
R.drawable.img33,
R.drawable.img34,
R.drawable.img35,
R.drawable.img36,
R.drawable.img37,
R.drawable.img38,
R.drawable.img39,
R.drawable.img40
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//FullScreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FL AG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.layout_activity_menu_terol l);
imgPos = imgPrePos = xDown = xUp = 0;
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
iSwitch = (ImageSwitcher)findViewById(R.id.switcher);
slideInLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
slideInRight = AnimationUtils.loadAnimation(this, R.anim.slide_in_right);
//iSwitch.setOutAnimation(AnimationUtils.loadAnimati on(this, android.R.anim.fade_out));
iSwitch.setFactory(new ViewFactory() {
@Override
public View makeView() {
// TODO Auto-generated method stub
ImageView iv = new ImageView(ClsImageSwitcher.this);
iv.setScaleType(ScaleType.FIT_XY);
return iv;
}
});
iSwitch.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
xDown = (int) event.getX();
break;
case MotionEvent.ACTION_UP:
xUp = (int) event.getX();
if (xUp < xDown) {
iSwitch.setInAnimation(slideInRight);
imgPos++;
if(imgPos > imgList.length-1){
imgPos = 0;
}
} else if (xUp > xDown ) {
iSwitch.setInAnimation(slideInLeft);
imgPos--;
if (imgPos < 0) {
imgPos = imgList.length-1;
}
}
//mToast.cancel();
mToast.setText((imgPos+1)+"/40");
mToast.show();
iSwitch.setImageResource(imgList[imgPos]);
iSwitch.setBackgroundResource(imgList[imgPrePos]);
imgPrePos = imgPos;
break;
}
return true;
}
});
//iSwitch.setBackgroundResource(R.drawable.)
iSwitch.setImageResource(imgList[0]);
}
}
با این کلاس(چند خط ) از کد مشکل دارم
@Override
public View makeView() {
// TODO Auto-generated method stub
ImageView iv = new ImageView(ClsImageSwitcher.this);
iv.setScaleType(ScaleType.FIT_XY);
return iv;
}
});
از ClsImageSwitcher ایراد میگیره ایکلیپس
خی میتونید یک توضیحی درباره ی کلاس بالا بدید؟
که وضیفش چیه و چرا از ClsImageSwitcher مشکل میگیره و اصلا ClsImageSwitcher چی هست؟
یک کد گالری با این قابلیت که وقتی انگشت رو به چپ و راست میکشی عکس هم تغیر کنه :
package com.example.aksdoni;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.Toast;
import android.widget.ViewSwitcher.ViewFactory;
public class Activity_Menu_Teroll extends Activity{
int imgPos, imgPrePos;
ImageSwitcher iSwitch;
Animation slideInLeft, slideInRight;
Toast mToast;
int xDown, xUp;
int[] imgList = {
R.drawable.img1,
R.drawable.img2,
R.drawable.img3,
R.drawable.img4,
R.drawable.img5,
R.drawable.img6,
R.drawable.img7,
R.drawable.img8,
R.drawable.img9,
R.drawable.img10,
R.drawable.img11,
R.drawable.img12,
R.drawable.img13,
R.drawable.img14,
R.drawable.img15,
R.drawable.img16,
R.drawable.img17,
R.drawable.img18,
R.drawable.img19,
R.drawable.img20,
R.drawable.img21,
R.drawable.img22,
R.drawable.img23,
R.drawable.img24,
R.drawable.img25,
R.drawable.img26,
R.drawable.img27,
R.drawable.img28,
R.drawable.img29,
R.drawable.img30,
R.drawable.img31,
R.drawable.img32,
R.drawable.img33,
R.drawable.img34,
R.drawable.img35,
R.drawable.img36,
R.drawable.img37,
R.drawable.img38,
R.drawable.img39,
R.drawable.img40
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//FullScreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FL AG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.layout_activity_menu_terol l);
imgPos = imgPrePos = xDown = xUp = 0;
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
iSwitch = (ImageSwitcher)findViewById(R.id.switcher);
slideInLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
slideInRight = AnimationUtils.loadAnimation(this, R.anim.slide_in_right);
//iSwitch.setOutAnimation(AnimationUtils.loadAnimati on(this, android.R.anim.fade_out));
iSwitch.setFactory(new ViewFactory() {
@Override
public View makeView() {
// TODO Auto-generated method stub
ImageView iv = new ImageView(ClsImageSwitcher.this);
iv.setScaleType(ScaleType.FIT_XY);
return iv;
}
});
iSwitch.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
xDown = (int) event.getX();
break;
case MotionEvent.ACTION_UP:
xUp = (int) event.getX();
if (xUp < xDown) {
iSwitch.setInAnimation(slideInRight);
imgPos++;
if(imgPos > imgList.length-1){
imgPos = 0;
}
} else if (xUp > xDown ) {
iSwitch.setInAnimation(slideInLeft);
imgPos--;
if (imgPos < 0) {
imgPos = imgList.length-1;
}
}
//mToast.cancel();
mToast.setText((imgPos+1)+"/40");
mToast.show();
iSwitch.setImageResource(imgList[imgPos]);
iSwitch.setBackgroundResource(imgList[imgPrePos]);
imgPrePos = imgPos;
break;
}
return true;
}
});
//iSwitch.setBackgroundResource(R.drawable.)
iSwitch.setImageResource(imgList[0]);
}
}
با این کلاس(چند خط ) از کد مشکل دارم
@Override
public View makeView() {
// TODO Auto-generated method stub
ImageView iv = new ImageView(ClsImageSwitcher.this);
iv.setScaleType(ScaleType.FIT_XY);
return iv;
}
});
از ClsImageSwitcher ایراد میگیره ایکلیپس
خی میتونید یک توضیحی درباره ی کلاس بالا بدید؟
که وضیفش چیه و چرا از ClsImageSwitcher مشکل میگیره و اصلا ClsImageSwitcher چی هست؟