Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ViewPager dimension

Does the ViewPager have to be the only object present inside the activity layout? I'm trying to implement something like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/reader_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<android.support.v4.view.ViewPager
    android:id="@+id/page_viewer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Gallery
    android:id="@+id/miniatures_gallery"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" /></LinearLayout>

Where should I have a big pager scrolling in the top (and I have it) and a smaller gallery scrolling under that. This shows me only the pager and not the gallery. Any suggestion?

like image 673
Lorenzo Sciuto Avatar asked Dec 16 '11 09:12

Lorenzo Sciuto


People also ask

What is the difference between ViewPager and ViewPager 2?

ViewPager2 is an improved version of the ViewPager library that offers enhanced functionality and addresses common difficulties with using ViewPager . If your app already uses ViewPager , read this page to learn more about migrating to ViewPager2 .

Is ViewPager deprecated?

This method may be called by the ViewPager to obtain a title string to describe the specified page. This method is deprecated. This method should be called by the application if the data backing this adapter has changed and associated views should update.

What is Android ViewPager?

ViewPager in Android allows the user to flip left and right through pages of data. In our android ViewPager application we'll implement a ViewPager that swipes through three views with different images and texts.

What is Tablayout and ViewPager in Android?

Tab layout are visible below toolbar with View pager, used to create swipeable views . Tabs are designed to work with fragments. Use them to swipe fragments in view pager. In this article, we are going to show you how to implement material design tabs in your android app.


1 Answers

The ViewPager does not support wrap_content as it (usually) never have all its children loaded at the same time, and can therefore not get an appropriate size (the option would be to have a pager that changes size every time you have switched page).

You can however set a precise dimension (e.g. 150dp) and match_parent works as well.
You can also modify the dimensions dynamically from your code by changing the height-attribute in its LayoutParams.

like image 161
Jave Avatar answered Sep 20 '22 04:09

Jave