View Full Version : ViewPager
  
mnakhaeipoor
یک شنبه 10 خرداد 1394, 19:22 عصر
سلام رفقا :چشمک:
همونطور که در تصویر زیر میبینید وقتی نوار پایین سمت راست رو می کشیم یه صفحه ی دیگه توسط viewpager باز میشه
131840
من تو نت برا ساخت viewpager سرچ کردم هرچی میومد درباره ساخت Tab با viewpager بود اونی که من میخوام رو نتونستم پیدا کنم :گریه:
کسی از دوستان میتونه لطف کنه یه منبع آموزشی برا ساخت یه چنین چیزی بهم معرفی کنه ؟؟
دمتون گرم :تشویق:
mnakhaeipoor
دوشنبه 11 خرداد 1394, 09:11 صبح
کسی راهی به ذهنش نمیرسه ؟ :ناراحت:
nafasak
سه شنبه 12 خرداد 1394, 10:12 صبح
میتونی از ViewFlipper استفاده کنی:
http://www.warriorpoint.com/blog/2009/05/29/android-switching-screens-by-dragging-over-the-touch-screen/
توی این مثال یک آبجکت برای swipe به صفحه اضافه کن و onTouch رو به اون نسبت بده.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >
    <ViewFlipper
        android:id="@+id/details"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:orientation="vertical" >
            <TextView
                android:id="@+id/tv_country"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Country"
                android:textColor="#000000"
                android:textSize="18px"
                android:textStyle="bold" >
            </TextView>
            <Spinner
                android:id="@+id/spinner_country"
                android:layout_width="200px"
                android:layout_height="55px"
                android:text="" >
            </Spinner>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:orientation="vertical" >
            <TextView
                android:id="@+id/tv_income"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Income"
                android:textColor="#000000"
                android:textSize="18px"
                android:textStyle="bold" >
            </TextView>
            <EditText
                android:id="@+id/et_income"
                android:layout_width="200px"
                android:layout_height="55px"
                android:text="" >
            </EditText>
        </LinearLayout>
    </ViewFlipper>
    <TextView
        android:id="@+id/tvHandle"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#abcdef"
        android:text="handle" >
    </TextView>
</LinearLayout>
public class ActivitySwipeManuall extends Activity {
    float downXValue;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set main.XML as the layout for this Activity
        setContentView(R.layout.activity_swipe);
        // Add these two lines
        TextView tvHandle = (TextView) findViewById(R.id.tvHandle);
        tvHandle.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                // Get the action that was done on this touch event
                switch (arg1.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    // store the X value when the user's finger was pressed down
                    downXValue = arg1.getX();
                    break;
                }
                case MotionEvent.ACTION_UP: {
                    // Get the X value when the user released his/her finger
                    float currentX = arg1.getX();
                    // going backwards: pushing stuff to the right
                    if (downXValue < currentX) {
                        // Get a reference to the ViewFlipper
                        ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                        // Set the animation
                        vf.setAnimation(AnimationUtils.loadAnimation(Activ itySwipeManuall.this, R.anim.push_left_out));
                        // Flip!
                        vf.showPrevious();
                    }
                    // going forwards: pushing stuff to the left
                    if (downXValue > currentX) {
                        // Get a reference to the ViewFlipper
                        ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                        // Set the animation
                        vf.setInAnimation(AnimationUtils.loadAnimation(Act ivitySwipeManuall.this, R.anim.push_left_in));
                        // Flip!
                        vf.showNext();
                    }
                    break;
                }
                }
                // if you return false, these actions will not be recorded
                return true;
            }
        });
        // Add a few countries to the spinner
        Spinner spinnerCountries = (Spinner) findViewById(R.id.spinner_country);
        ArrayAdapter countryArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, new String[] { "Canada", "USA" });
        spinnerCountries.setAdapter(countryArrayAdapter);
    }
}
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.