ScrollView goes up in Multiple Fragments - android

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"

Related

static buttons inside a scrollView android

I am making an xml layout file consists of 3 parts:
Part 1: some information and image about a place.
Part 2: two horizontal Buttons.
Part 3: RecyclerView of some people reviews.
This is my layout file:
<ScrollView
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:name="com.example.abdo.foodproject.OneItemFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.abdo.foodproject.OneItemFragment"
tools:layout="#layout/activity_item"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/oneitem_background_theme"
android:orientation="vertical"
android:weightSum="13"
>
<LinearLayout>
(...) <!--part 1-->
</LinearLayout>
<LinearLayout <!--part 2-->
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/review_list"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/reviews"
android:background="#color/colorPrimaryDark"
/>
<Button
android:id="#+id/bestMeal_list"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryLight"
android:text="#string/best_meal"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView <!--part 3-->
android:id="#+id/recyclerViewItem"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
I want to have the buttons fixed at my screen, at the top of the window, without losing their view from the scrolling.
Does anyone have any idea how to do so?
You can use CoordinatorLayout to achive such an affect.
CoordinatorLayout has 2 childs which one has also 2 childs as you wish
AppBarLayout: is a linear layout with vertical orientation. It's contents can disappear or pin according to "app:layout_collapseMode" attribute when scroll completed.
1.1. CollapsingToolbarLayout: you can put your "part 1" view in this place with app:layout_collapseMode="parallax" to parallax when disappearing.
1.2. Fixed view. LinearLayout: feel free to replace with your "part 2" view. This part will be pinned when scroll completed.
Scrollable view: it is RecyclerView in your example.
Final code should be similar like:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#android:color/transparent"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<!--part 1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax">
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<!--part 2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weight_sum="2">
<Button
android:id="#+id/review_list"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/reviews"
android:background="#color/colorPrimaryDark"
/>
<Button
android:id="#+id/bestMeal_list"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryLight"
android:text="#string/best_meal"
/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<!--part 3-->
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.CoordinatorLayout>

Center fragment in ViewPager

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.

Listview Upper Bounds and Lower Bounds do not interact when the user reaches the limits

My listview is in a scrollable view, when I reach the Upper bound limit or the lower bound limit the listview doesn't show the blue circle from the bounds. How can I make the layout shows it?
After adding the overScrollMode=Always still it is not working, This Layout is added in the ScrollingActivity sample provided by Android.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:overScrollMode="always"
android:fillViewport="true>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/snackBarLocation">
</android.support.design.widget.CoordinatorLayout>
<ListView
android:id="#+id/list2"
android:layout_width="match_parent"
android:layout_height="55dp"/>
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="50dp"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="50dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text"
/>
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="10dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
This is called "over-scroll".
You can change the over-scroll mode via XML:
android:overScrollMode="always"
Or via Java:
setOverScrollMode(OVER_SCROLL_ALWAYS);
See https://developer.android.com/reference/android/widget/ScrollView.html#setOverScrollMode(int) for more information.

Custom view in fragment overlap other fragment on samsung device

I am facing a problem of overlapping fragments when i inflate fragments from below.
This is code in layout:
<FrameLayout
android:id="#+id/nonAdParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_blur">
<FrameLayout
android:id="#+id/collage_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_blur"
android:layout_marginBottom="#dimen/collageview_margin" />
<FrameLayout
android:id="#+id/menu_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorSecondary" />
</FrameLayout>
fragment "collage_view_container" contains 1 custom view and fragment "menu_footer" contains horizontal recyclerview.
This is code programmatically:
getSupportFragmentManager().beginTransaction()
.add(R.id.collage_view_container, new CollageContainerFrag().setLayoutModel(model)).commit();
FooterMenuFragment footerFrag = new FooterMenuFragment();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.slide_in_up, R.anim.no_anim)
.add(R.id.menu_footer, footerFrag).commit();
Issue: Custom view in "collage_view_container" fragment overlap horizontal recyclerview in "menu_footer" fragment on SAMSUNG device solely.
If i config line this code:
if (SystemUtils.isSamsungDevice()) {
getView().setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
then issue not appear but app will process "slowly". Otherwise, issues appear again.
This is whole code of view where "nonAdParent" framelayout located-in.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_blur"
android:clipChildren="true"
android:clipToPadding="false"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/>
<FrameLayout
android:id="#+id/adParent"
android:layout_width="match_parent"
android:layout_height="20dp"
android:visibility="gone" />
<FrameLayout
android:id="#+id/nonAdParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_blur">
<FrameLayout
android:id="#+id/collage_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_blur"
android:layout_marginBottom="#dimen/collageview_margin" />
<FrameLayout
android:id="#+id/menu_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorSecondary" />
</FrameLayout>
P.S. Please tell if some more code needed. Thanks in advance.
Replace your Frame layout(nonAdParent) part with the code given below
<RelativeLayout
android:id="#+id/nonAdParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_blur">
<FrameLayout
android:id="#+id/collage_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_blur"
android:layout_alignParentTop="true"
android:layout_marginBottom="#dimen/collageview_margin" />
<FrameLayout
android:id="#+id/menu_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_below="#+id/collage_view_container"
android:background="#color/colorSecondary" />
</RelativeLayout>

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).

Categories

Resources