Search code examples
androidandroid-layoutandroid-activityandroid-fragmentsandroid-sliding

Android slide left right UI


Android UI

I am trying to create a android UI with sliding feature in the middle of the screen. I only have MainAcitivity.java and trying to figure out how this can be done. Is there a control already in the sdk?. I see the sample which does the slide for the entire activity screen but not within the activity. Can you guys provide some ideas on how to do this. Thanks


Solution

  • You can use ViewPager... It is not necesary to use fragments.

    <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1" >
    </android.support.v4.view.ViewPager>
    
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:gravity="center"
            android:measureWithLargestChild="true"
            android:orientation="horizontal" >
    
    <Button
                android:id="@+id/first"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ABOUT THE IMAGE" >
            </Button>
    
    <Button
                android:id="@+id/last"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="SOME OTHER TEXT" >
    </Button>
    </LinearLayout>
    

    Here an example. http://www.androidbegin.com/tutorial/android-viewpager-gallery-images-and-texts-tutorial/

    Here an example using viewpager with fragments : http://manishkpr.webheavens.com/android-viewpager-example/