I have more than one Fragment in Viewpager ,on long press I want to scale down the Viewpager in the middle of screen as shown in below image. I want to show All fragments in Viewpager like android OS on Home screen. I am doing this by using library,
compile 'com.pixplicity.multiviewpager:library:1.0'
Here is xml file,
<com.pixplicity.multiviewpager.MultiViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bott_sidemenu"
app:matchChildWidth="#+id/vg" />
Here is child layout,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<FrameLayout
android:id="#+id/vg"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_centerInParent="true" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:background="#drawable/bg_page"
android:scaleType="centerInside"
android:src="#drawable/im_pixplicity"
tools:ignore="ContentDescription" />
</FrameLayout>
</RelativeLayout>
But all item size does not scale down inside the Viewpager Fragment. Is there a way to so way? Suggestion will be appreciated.
Related
I have a Fragment that contains a ViewPager which allows the user to swipe through three fragments.
Here's the problem: I want the ViewPager to have a background that remains fixed when the user swipes through the fragments. I tried setting an image in my drawable as the background of the ViewPager but that didn't work.. Here's my code:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue"
tools:context=".fragments.cash.WalletFragment">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:background="#drawable/revenue"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Although there are many ways to achieve this feat, this approach works for me:
Simply create a FrameLayout with two children: Your ViewPager and the view(s) you want to use as the background of your viewpager. Here's an example:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue"
tools:context=".fragments.cash.WalletFragment">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/my_smiling_face"/>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</RelativeLayout>
Note that you can replace the Imageview with a layout (e.g RelativeLayout) containing all the composite views you want your background to contain.
I hope this helps.. Merry coding!
What i really want is dividing the screen into two half vertically.The
top screen contain an activity that perform some certain task.The
another bottom screen contain the Tab Activity that can be swiped.
How can i do this?
You can use weight. Suppose:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/topLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" />
<LinearLayout
android:id="#+id/belowLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.design.widget.TabLayout>
</LinearLayout>
</LinearLayout>
I have a layout for an Activity that I'm trying to add a navigation drawer to.
The problem is, to work properly, I need to use:
<android.support.v4.widget.DrawerLayout
instead of:
<RelativeLayout
but it messes things up. My ProgressBar becomes much bigger, my RecyclerView doesn't work, the app logs me out when I click something, etc.
My layout XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.st.mf.UserAreaActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="#dimen/activity_vertical_margin"
android:background="#fff">
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp" />
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#layout/navigation_menu"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
How can I create my drawer menu without messing everything else up?
Any direct child View of a DrawerLayout that's not a drawer is considered a content View, and will be laid out to match_parent in both directions, regardless of the width and height attributes you've set on it. In your case - indeed, in most cases - you only need one content View, so the rest of the non-drawer Views should all be inside a single ViewGroup.
We'll place your ProgressBar and RecyclerView both inside a RelativeLayout that acts as the content View, where they'll keep the layout attributes you've set. For example:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.st.mf.UserAreaActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/activity_vertical_margin"
android:background="#fff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#layout/navigation_menu"
android:layout_gravity="start">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Note that the content View should always be listed before any drawers, to maintain proper z-ordering; i.e., to keep the drawers on top of the content.
I have an Activity with following XML
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<fragment android:name=".GalleryFragment"
android:id="#+id/gallery_fragment"
android:layout_width="match_parent"
android:layout_height="250dp"
android:transitionName="#string/transition">
...
</LinearLayout>
GalleryFragment with following XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:transitionName="#string/transition">
<android.support.v4.view.ViewPager
android:id="#+id/gallery_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
and ViewPager is hosting a couple (max 20) ImageFragments with following XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"/>
</LinearLayout>
Now I would like to add collapsable toolbar with parallax effect in such a way that ImageView from ImageFragment is the one which fades out as it collapses.
I have done this couple of times on much more simpler screens, I had only activity with toolbar and ImageView in it so the process was straightforward. But in this case I have no idea if this is even possible to implement because ImageView is inside Fragment which is inside ViewPager.
Does anyone know if this is even possible to implement and if so can you give me some tips.
Thanks is advance.
My Layout looks sth like this
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentTop="true"
android:background="#color/black" />
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/newsTabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_below="#+id/newsHeaderKenburn"
android:background="#drawable/background_news_tab"
app:pstsDividerColor="#color/transparent"
app:pstsIndicatorColor="#android:color/white"
app:pstsTextAllCaps="true" />
<android.support.v4.view.ViewPager
android:id="#+id/newsPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/newsTabs" />
</RelativeLayout>
When the Layout gets inflated it does not draw the Fragments of the Viewpager. I think its because ScrollView does not know when its layouted which size to expect, because the ViewPager has a flexible size depending on the fragments.
Is there a way to resize the Scrollview after the fragments are layouted ?