swipe some part of the screen

Sandip Armal Patil picture Sandip Armal Patil · Dec 20, 2012 · Viewed 7.8k times · Source

I am trying to design one screen which contain some swipe part. I have one screen with mapview, listview and some text. My Mapview is main part of swipe, if i swipe at left then contact will shown and if i swipe right then address will be display.
Here is my image. i am showing rounded part which i need to swipe. enter image description here
How can i implement this functionality in my app. I go through with one tutorial but it didn't help me. This tutorial teach how to swipe full screen but i need to swipe some part of the screen.
Is it possible. Give me some reference or hint. I didn't understand viewPager .

Answer

Sandip Armal Patil picture Sandip Armal Patil · Dec 27, 2012

Finally i got answer to swipe some part of the screen. in onCreate() you need to add following line

MyPagerAdapter adapter = new MyPagerAdapter();
     myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
     myPager.setAdapter(adapter);
     myPager.setCurrentItem(3);

I extend PagerAdapter class in my class.

private class MyPagerAdapter extends PagerAdapter {

    public int getCount() {
        return 3;
    }

    public Object instantiateItem(View collection, int position) {

        LayoutInflater inflater = (LayoutInflater) collection.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        int resId = 0;
        switch (position) {
        case 0: 
            resId = showHotelContact();             
            break;
        case 1:
            resId = showHotelAddress();         
            break;              
        case 2:     
            resId = showHotelMap();             
            break;      
        }

        View view = inflater.inflate(resId, null);
        ((ViewPager) collection).addView(view, 0);
        return view;
    }
 }   
public int showHotelMap()
{
    int resId;
    resId = R.layout.hotelmap;
    return resId;
}
public int showHotelAddress()
{
    int resId;
    resId = R.layout.hoteladdress;
    return resId;
}
public int showHotelContact()
{
    int resId;
    resId = R.layout.hotelcontact;
    return resId;
}

Here is my xml file

?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<android.support.v4.view.ViewPager
android:id="@+id/myfivepanelpager"
android:layout_width="wrap_content"
android:layout_height="186dp"
android:fadingEdge="vertical" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hotelName" />

</LinearLayout>