Gogo-the-Cat Gogo-the-Cat - 3 months ago 17
Android Question

Viewpager not for all screen

I have one layout includes textviews buttons and imageviews. I want to use Viewpager just one of the Imageviews to slide some images. But it slides whole screen.
I want to slide only Imageview that i want.



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"

tools:context="com.gogothecat.gok.lightroom.MainActivity"
android:background="#d9ab3b">

<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"


android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">

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

<ImageView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/imageView2"
android:layout_centerHorizontal="true"
android:layout_below="@+id/textView3" />

<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="50dp"
android:scaleType="fitStart"

android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:background="#ffffff"
android:layout_alignParentTop="true" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some text"
android:id="@+id/textView2"
android:layout_below="@+id/imageview"

android:background="#000000"
android:textColor="#FFFFFF"
android:textSize="35dp">
</TextView>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some long text"
android:id="@+id/textView3"
android:layout_below="@+id/textView2"


android:textColor="#000000"
android:background="#d9ab3b">
</TextView>

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:background="@drawable/abc_ic_ab_back_mtrl_am_alpha"

android:backgroundTint="#000000"
android:alpha="0.5"
android:allowUndo="true"
android:layout_alignTop="@+id/imageView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="149dp" />



Answer

So what I did was just add another layout to the xml before the viewpager. Like So

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">
    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_item_view" />

    <android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v4.view.PagerTabStrip
        android:id="@+id/pager_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textAppearance="@style/PagerTabStripText"
        />

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

</LinearLayout>

It displays my first layout and then the viewpager with fragments below it