Center fragment in ViewPager - android

I trying to achieve one layout like this:
The problem is that i cant center fragment on viewpager. I already try to change gravitys, and everything but i cant. There is some of mycode:
<android.support.design.widget.CollapsingToolbarLayout
>
<RelativeLayout
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:gravity="center" />
</RelativeLayout>
(...)
</android.support.design.widget.CollapsingToolbarLayout>
Fragment child have that code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/infos"
android:weightSum="3"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
(...)</LinearLayout>
With this code im geting something like this:

Please update your layout like this:
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_marginTop="25dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
/>
Feel free to tailor padding/height to fit your UI.

Related

RecyclerView pull up loading data response delay in CoordinatorLayout AppBarLayout

My xml layout is shown below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/root_literature_fm"
android:layout_width="match_parent"
android:layout_height="match_parent">
<net.cnki.tCloud.view.widget.TitleBar
android:id="#id/base_titlebar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.CoordinatorLayout
android:id="#+id/root_literature_fm_literature_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/base_titlebar"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
app:layout_scrollFlags="scroll|enterAlways|snap">
<com.facebook.drawee.view.SimpleDraweeView
android:id="#+id/sdv_magazine_cover"
android:layout_width="90dp"
android:layout_height="120dp"
android:padding="13dp"
fresco:actualImageScaleType="centerCrop"
fresco:placeholderImage="#mipmap/side_surface"
fresco:placeholderImageScaleType="centerCrop"/>
<TextView
android:id="#+id/tv_magazine_name"
style="#style/TextItemMagazineTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/sdv_magazine_cover"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="55dp"
tools:text="title"/>
<TextView
android:id="#+id/tv_magazine_date"
style="#style/TextItemMagazineSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/sdv_magazine_cover"
android:ellipsize="end"
android:paddingTop="55dp"
tools:text="1922"/>
</RelativeLayout>
<include layout="#layout/layout_literature_filter"/>
</android.support.design.widget.AppBarLayout>
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="#+id/xrv_literature"
android:name="net.cnki.tCloud.view.fragment.LiteratureFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
app:layoutManager="LinearLayoutManager"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<ViewStub
android:id="#+id/vs_no_literature"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/base_titlebar"
android:layout="#layout/layout_literature_unbind"/>
My problem is delayed response when i slide up the screen to load data. The link is a video of the issue.https://www.youtube.com/watch?v=VaaAl-omBiY
I think this problem is setting behavior.This touch event is a delay passed to RecyclerView.
Please help me this problem has been bothering me for a long time.
this is a bug of supportlibrary,and not fixed in 27.1.0
https://issuetracker.google.com/issues/66996774
try https://gist.github.com/chrisbanes/8391b5adb9ee42180893300850ed02f2, it works

ScrollView goes up in Multiple Fragments

Hiii,
I am Struggling with ScrollView issue for long time.but unable to solve the issue.
Issue is
I Created one Layout in which I have multiple frame Layouts
Each frame layout is used to contain single fragments.(eg. frame2 is used for fragment 2,frame 3 fro fragment 3 etc.)
frame layouts are oneBelow other.
this is Code :
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:fitsSystemWindows="false"
android:id="#+id/svStudentData"
android:layout_marginTop="5dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/lnlFrames"
android:visibility="visible">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frame2"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame3"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame4"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame5"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame6"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame7"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame8"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame9"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame10"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame11"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame12"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame13"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame14"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame15"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame16"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame17"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame18"></FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/frame19"></FrameLayout>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/btnSave"
android:text="Save"
android:visibility="gone"
android:layout_margin="10dp"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Data is Already saved "
android:visibility="gone"
android:textSize="28sp"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:textColor="#color/white"
android:typeface="sans"
android:gravity="center_horizontal|center_vertical"
android:id="#+id/tvNoData"/>
</LinearLayout>
</ScrollView>
fragments are one below other like frag1 then frag2 etc.
Now my question is when my first fragment visibility is gone then the second fragment comes at the top but it goes up.means we cant see the second fragment from the top we have to scroll up to see the top portion of the second fragment.
I tried using things like..
scroll_view.pageScroll(View.FOCUS_UP) ;
also
scroll_view.fullScroll(View.FOCUS_UP) ;
and
scroll_view.smoothScrollTo(0,0);
but none worked for me
/Just Simply try to use NestedScrollView instead of ScrollView/
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedscrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<!-- <include layout="#layout/project_content_main" />-->
Note: Include you LineaeLayout like above example.
</android.support.v4.widget.NestedScrollView>
And don't forget to add android support design Library in Builf.gradle file
compile 'com.android.support:design:your_version'
Try puting this in your scrollView xml tag
android:descendantFocusability="beforeDescendants"

Add imageView to coordinatorLayout

Here is my coordinator layout. Everything is ok, I can see everything.
But I can't see the ImageView. In code I am initializing ImageView correctly and have an object. I need Image view in center of screen.
If I change ImageView to button I see button in center of screen, but if I change to something other I canĀ“t seen that element.
Please how Can I add ImageView to coordinatorLayout?
This code is in coordinatorlayout.
Thank you.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:id="#+id/status_btn"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:background="#color/red" />
<Button
android:id="#+id/delete_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Smazat"
android:visibility="gone" />
<include
layout="#layout/panel_camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<!--height a width se nastavuje dynamicky-->
<LinearLayout
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<RelativeLayout
android:id="#+id/bottom_sheet_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/header_vg"
android:layout_width="match_parent"
android:layout_height="#dimen/vision_bottom_sheet_header_height"
android:layout_alignParentTop="true"
android:background="#color/gray_header_vision"
android:gravity="center">
<TextView
android:id="#+id/header_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="#color/white"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/vision_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header_vg"
android:background="#color/white"
android:scrollbars="vertical"
android:visibility="gone" />
<include
android:id="#+id/empty_vg"
layout="#layout/panel_vision_tutorial"
android:layout_width="match_parent"
android:layout_height="#dimen/vision_bottom_sheet_item_height"
android:layout_below="#+id/header_vg" />
</RelativeLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Here is my panel_camera_preview:
<my_package.CameraSourcePreview
android:id="#+id/camera_preview"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray">
<my_package.GraphicOverlay
android:id="#+id/face_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</my_package.CameraSourcePreview>
CoordinatorLayout is a FrameLayout, thus the last View in order overlays the previous ones. Then Imageview results not visible because it is covered by your panel_camera_preview, while Button results visible, but only if is running on Lollipop or greater, cause its default elevation (2dp).

Using Floating Action Button With Tabs

I am using floating action button with slidingtablayout, but when i use fab in fragments every tab will have its own fab, and transition looks bad like this video from google design
http://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQsNVRkV3FZMktvMWc/components-buttons-fab-behavior_06_xhdpi_009.webm
When i use fab in the viewpager it shrinks fragments like in the link
https://drive.google.com/file/d/0By6vpKpg_w4tcEJQUUlRazd0VEk/view?usp=sharing
Here is my code activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.smooth.www.smooth.SlidingTabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:background="#color/ColorPrimary"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
and one of my tabs
<android.support.design.widget.CoordinatorLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#f0f0f0"
>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/tab_main_swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.RecyclerView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/main_recycler"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:id="#+id/main_fab"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:transitionName="#string/fab_transition_name"
android:src="#drawable/fab_image"
app:layout_anchor="#id/main_recycler"
app:layout_anchorGravity="bottom|right|end"
/>
</android.support.design.widget.CoordinatorLayout>
what can i do to for transitions to look good??
Looks like you ar using a LinearLayout or something, instead of RelativeLayout. Can you post code snippets?

android- How to use ViewPager inside scrollView

I've a layout that has 3 parts . One of them is viewpager . I need to scroll the screen .
i've this code but the problem is this ,the viewpager is not showing at all .
<ScrollView 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:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/s11" />
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="#CC0001"
android:textColor="#FFFFFF" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
How can I make viewpager to wrap the free space and fill the parent and show its content ?
thanks you

Categories

Resources