shikher.mishra shikher.mishra - 1 month ago 15
Android Question

Button is not getting displayed after the ViewPager tag

I am creating a gallery and in this I am using a ViewPager tag to create a gallery. Just down to it I want to create a button of "Back" whose actions I am specifying in the "onclick" function.
My Button is not getting displayed in the view page of the Gallery.Just the gallery is appearing not the button.

This is the xml page of the activity.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.hsports.bandpop.GalleryForBand">



<android.support.v4.view.ViewPager
android:layout_width="360dp"
android:layout_height="360dp"
android:id="@+id/pager"

>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/BackButton"
android:onClick="goBackToDetailPage"

/>
</android.support.v4.view.ViewPager>
</LinearLayout>

Answer

This is not possible to have a view within viewpager.

Alternately, you can use

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hsports.bandpop.GalleryForBand">



    <android.support.v4.view.ViewPager
        android:layout_width="360dp"
        android:layout_height="360dp"
        android:id="@+id/pager" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/BackButton"
        android:onClick="goBackToDetailPage"

        />
</LinearLayout>

Or instead use LinearLayout use RelativeLayout