आप चाहें, तो आप उपयोग कर सकते हैं एंड्रॉयड सहायता पैकेज - http://developer.android.com/sdk/compatibility-library.html
कम प्रयास आप अपनी गतिविधि को संशोधित कर सकते हैं
टुकड़ों का उपयोग करने के लिए ताकि आपके टैब में यूट्यूब ऐप की तरह संक्रमण एनिमेशन हो सकें। यह इस प्रकार से लागू करने के लिए का एक नमूना कोड है - http://developer.android.com/sdk/compatibility-library.html
संपादित करें: आप सहायता पैकेज का उपयोग नहीं करना चाहते हैं, तो हो सकता है इस कार्यान्वयन
निजी वर्ग MyGestureDetector में मदद मिलेगी SimpleOnGestureListener {
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;
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//get density
final DisplayMetrics metrics = getResources().getDisplayMetrics();
final float density = metrics.density;
//System.out.println(" in onFling() :: ");
//off path
if (Math.abs(e1.getY() - e2.getY()) > density*SWIPE_MAX_OFF_PATH)
return false;
//fling from right to left
if (e1.getX() - e2.getX() > density*SWIPE_MIN_DISTANCE && Math.abs(velocityX) > density*SWIPE_THRESHOLD_VELOCITY) {
//if the first tab is selected
if(currentSelection.equalsIgnoreCase(getString(R.string.tab_details_info))) {
//switch to second tab and save current selection
tabs.setCurrentTab(1);
currentSelection = tabs.getCurrentTabTag();
}
//if the second tab is selected
else if(currentSelection.equalsIgnoreCase(getString(R.string.tab_details_details))) {
//switch to second tab and save current selection
tabs.setCurrentTab(2);
currentSelection = tabs.getCurrentTabTag();
}
}
//fling from left to right
else if (e2.getX() - e1.getX() > density*SWIPE_MIN_DISTANCE && Math.abs(velocityX) > density*SWIPE_THRESHOLD_VELOCITY) {
//if the second tab is selected
if(currentSelection.equalsIgnoreCase(getString(R.string.tab_details_details))) {
//switch to second tab and save current selection
tabs.setCurrentTab(0);
currentSelection = tabs.getCurrentTabTag();
}
//if the third tab is selected
else if(currentSelection.equalsIgnoreCase(getString(R.string.tab_details_company))) {
//switch to second tab and save current selection
tabs.setCurrentTab(1);
currentSelection = tabs.getCurrentTabTag();
}
}
return super.onFling(e1, e2, velocityX, velocityY);
}
}
फैली
और उसके बाद आपके टैब पर श्रोता बदल गया उचित एनीमेशन लोड करें क्योंकि आप जानते हैं कि इशारा से पहले कौन सा चुना गया था, और जिसे हम बाद में स्विच कर रहे हैं।
@Override
public void onTabChanged(String tabId) {
//if the first tab is selected
if(currentSelection.equalsIgnoreCase(getResources().getString(R.string.tab_details_info))) {
//if we switch to second
if(tabId.equalsIgnoreCase(getResources().getString(R.string.tab_details_details))) {
linearInfo.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_left_out));
linearDetails.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_left_in));
linearCompany.setAnimation(null);
}
//if switch to third
else if(tabId.equalsIgnoreCase(getResources().getString(R.string.tab_details_company))) {
linearInfo.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_left_out));
linearDetails.setAnimation(null);
linearCompany.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_left_in));
}
}
//if the second tab is selected
else if(currentSelection.equalsIgnoreCase(getResources().getString(R.string.tab_details_details))) {
//if we switch to first
if(tabId.equalsIgnoreCase(getResources().getString(R.string.tab_details_info))) {
linearInfo.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_right_in));
linearDetails.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_right_out));
linearCompany.setAnimation(null);
}
//if switch to third
else if(tabId.equalsIgnoreCase(getResources().getString(R.string.tab_details_company))) {
linearInfo.setAnimation(null);
linearDetails.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_left_out));
linearCompany.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_left_in));
}
}
//if the third tab is selected
else if(currentSelection.equalsIgnoreCase(getResources().getString(R.string.tab_details_company))) {
//if we switch to first
if(tabId.equalsIgnoreCase(getResources().getString(R.string.tab_details_info))) {
linearInfo.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_right_in));
linearDetails.setAnimation(null);
linearCompany.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_right_out));
}
//if switch to second
else if(tabId.equalsIgnoreCase(getResources().getString(R.string.tab_details_details))) {
linearInfo.setAnimation(null);
linearDetails.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_right_in));
linearCompany.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_right_out));
}
}
currentSelection = tabId;
}
};
इसके अलावा, आप (और शायद अलग स्क्रीन घनत्व के लिए खाते में यह निर्धारित करते समय एक इशारा एक कड़ी चोट कार्रवाई है) कस्टम इशारा डिटेक्टर आप के साथ onTouchListener अधिभावी द्वारा इशारा पकड़ने के लिए की जरूरत है
विस्तृत उत्तर के लिए खेद है , लेकिन मुझे उम्मीद है कि यह मदद करता है :)
यह उपयोगी हो सकता है: http://www.techienjoy.com/android-tab-example.php – Nimit