आप ViewFlipper उपयोग कर रहे हैं छवियों
slideShowBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
runnable = new Runnable() {
@Override
public void run() {
handler.postDelayed(runnable, 3000);
imageFrame.showNext();
}
};
handler.postDelayed(runnable, 500);
}
});
प्रदर्शित करने के लिए इस कोड का प्रयास करें इसका इस्तेमाल को रोकने के लिए handler.removeCallbacks(runnable);
public class PhotoSlideShowActivity extends Activity implements OnClickListener {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
ViewFlipper imageFrame;
RelativeLayout slideShowBtn;
Handler handler;
Runnable runnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_slideshow_main);
imageFrame = (ViewFlipper) findViewById(R.id.imageFrames);
//get sd card path for images
File parentFolder = new
File(Environment.getExternalStorageDirectory()
.getAbsolutePath()
+ "/images");
addFlipperImages(imageFrame, parentFolder);
// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event))
return true;
else
return false;
}
};
handler = new Handler();
imageFrame.setOnClickListener(PhotoSlideShowActivity.this);
imageFrame.setOnTouchListener(gestureListener);
slideShowBtn = (RelativeLayout) findViewById(R.id.slideShowBtn);
slideShowBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
runnable = new Runnable() {
@Override
public void run() {
handler.postDelayed(runnable, 3000);
imageFrame.showNext();
}
};
handler.postDelayed(runnable, 500);
}
});
}
private void addFlipperImages(ViewFlipper flipper, File parent) {
int imageCount = parent.listFiles().length;
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
for (int count = 0; count < imageCount - 1; count++) {
ImageView imageView = new ImageView(this);
Bitmap imbm = BitmapFactory.decodeFile(parent.listFiles()[count]
.getAbsolutePath());
imageView.setImageBitmap(imbm);
imageView.setLayoutParams(params);
flipper.addView(imageView);
}
}
class MyGestureDetector extends SimpleOnGestureListener {
@SuppressWarnings("static-access")
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
slideShowBtn = (RelativeLayout) findViewById(R.id.slideShowBtn);
slideShowBtn.setVisibility(slideShowBtn.VISIBLE);
handler.removeCallbacks(runnable);
runnable = new Runnable() {
@Override
public void run() {
slideShowBtn.setVisibility(slideShowBtn.INVISIBLE);
}
};
handler.postDelayed(runnable, 2000);
return true;
}
@SuppressWarnings("static-access")
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
slideShowBtn = (RelativeLayout) findViewById(R.id.slideShowBtn);
slideShowBtn.setVisibility(slideShowBtn.VISIBLE);
handler.removeCallbacks(runnable);
runnable = new Runnable() {
@Override
public void run() {
slideShowBtn.setVisibility(slideShowBtn.INVISIBLE);
}
};
handler.postDelayed(runnable, 2000);
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
handler.removeCallbacks(runnable);
imageFrame.setInAnimation(inFromRightAnimation());
imageFrame.setOutAnimation(outToLeftAnimation());
imageFrame.showNext();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
handler.removeCallbacks(runnable);
imageFrame.setInAnimation(inFromLeftAnimation());
imageFrame.setOutAnimation(outToRightAnimation());
imageFrame.showPrevious();
}
} catch (Exception e) {
// nothing
}
return false;
}
}
@Override
public void onClick(View view) {
}
private Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.2f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
private Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.2f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
private Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.2f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(500);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
private Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.2f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
}
लेआउट
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/imageFrames"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/screen_background_dark" >
</ViewFlipper>
<RelativeLayout
android:id="@+id/slideShowBtn"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:gravity="center" android:visibility="invisible">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#33FFFFFF"
android:gravity="center"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:paddingTop="1dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#66000000"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:text="Slideshow"
android:textSize="18dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
कोई दोनों उपयोगी मैं खोलना चाहते हैं नहीं कर रहे हैं पूरी तरफ छवि, स्लाइडर के साथ पूर्ण स्क्रीन छवि को कैसे खोलें मैन्युअल रूप से बाएं और दाएं स्लाइड करें? – UMAR
बस एक पूर्णस्क्रीन ImageView (fill_parent को सेट चौड़ाई और ऊंचाई) बनाएं और ऑनफलिंग इशारा को पहचानने के लिए एक सरल जेस्चर लिस्टर जोड़ें।जब यह पहचाना जाता है, छवि को ImageView में स्विच करें। – reflog
एनीमेशन के बारे में क्या? इशारे के बारे में क्या? चुटकी और ज़ूम के बारे में क्या? बारी बारी से? फसल? वॉलपेपर के रूप में सेट करें? आदि समस्या यह है कि 3 डी गैलरी का पुन: उपयोग नहीं किया जा सकता !!! –