In my xml file I have a Linear layout that has a ViewPager for showing images and another Linear layout that contains previous and Next buttons for selecting images.My xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/goto_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="first" >
</Button>
<Button
android:id="@+id/goto_last"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="last" >
</Button>
</LinearLayout>
</LinearLayout>
My problem is that the ViewPager is taking full screen and the Linearlayout with previous next buttons is not showing up because there is no space left to draw this LinearLayout.
I am using Fragments to populate ViewPager with views.The xml file for the fragment view that goes into ViewPager is:
<ImageView
android:id="@+id/ItemImage"
android:layout_width="320dp"
android:layout_height="180dp" />
<TextView
android:id="@+id/ItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:layout_marginBottom="5dp"
android:textColor="#ffffffff"
android:textStyle="bold" />
</FrameLayout>
The output i am getting after rendering is in this manner:
1.image ( covering 45% screen height)
2.blank space (covering 45% screen height)
3.Textview (covering rest of the 10% screen height)
The output i want is :
1.image ( covering 45% screen height)
2.Textview (covering 10% screen height)
3.LinearLayout for Buttons (covering rest of the 45% screen height)
Just use a RelativeLayout and use the attributes like `
android:layout_below
until you achieve the position you desire. Relative Layout is your friend in these cases.
Use RelativeLayout. Add your buttons to the bottom with alignParentBottom="true"
. Then add the ViewPager with layout_above="@id/buttons"
Just give those to viewpager:
android:layout_height="0dp"
android:layout_weight="1"
The problem with viewpagers are they don't know the size since each fragment could possibly be a different size. You have to manually set the viewpager's, not wrap_content. I recommend setting a weight to all the items in the outer linear layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With