how to scroll pull to refresh scrollview in normal scrollview - android

Here is my layout xml.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/garae_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background"
android:fillViewport="true"
android:focusableInTouchMode="false" >
<RelativeLayout>
...
<com.handmark.pulltorefresh.library.PullToRefreshScrollView>
<LinearLayout/>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
</RelativeLayout>
</ScrollView>
I already tried the solution in this link:
ScrollView Inside ScrollView
However, it didn't work. How can do use child PullToRefreshScrollView??
Please help me.

If I understand your question, you want to implement a Pull to refresh in your Scrollview. Instead, to use the library you are using, I would suggest you to implement a SwipeRefreshLayout
https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
It is a layout that implements a pull-to-refresh like in the application of Google+ or Gmail.
Here's an example implementing SwipeRefreshLayout in your xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/garae_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
NOTE
It is highly not recommended to put a Scrollview/Listview inside a Scrollview/Listview. The first reason is about the performance and Romain Guy explains that in one video https://www.youtube.com/watch?v=wDBM6wVEO70

Related

Android RecyclerView scrollbar doesn't work

the scrollbar in my RecyclerView doesn't work, I mean I can scroll the RecyclerView with touch, I also can see the scrollbar but it's can not move
Before ask the question I also tried with some answers here for example:
https://www.dev2qa.com/android-recyclerview-horizontal-scroll-example/
Android RecyclerView Scroll not working after Layout edit
But none of them work for me
Below is my code, thanks in advance
Layout file:
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HexViewActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_hex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:scrollbarSize="15dp"
android:scrollbars="vertical" />
</ScrollView>
Code to create the view
RecyclerView recyclerView = findViewById(R.id.rv_hex);
recyclerView.setLayoutManager(new LinearLayoutManager(HexConstant.app_ontext));
m_fileDataAdapter = new FileDataAdapter(HexConstant.app_ontext, files[0]);
recyclerView.setAdapter(m_fileDataAdapter);
recyclerView.setNestedScrollingEnabled(true);
Is there any example for Scrollbar + recyclerView, pls let me know
Change the outer layout with scroll view layout.
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HexViewActivity">
<!-- Your stuff here -->
</ScrollView>
Have you tried using RecyclerView's attribute app:fastScrollEnabled="true"?
Check the full answer here. https://stackoverflow.com/a/46026362/6455501

Android-Last item of the ListView is not visible

I have added the ListView inside ViewPager, as soon as the page is loaded the first tab is selected and the last item of the list does not show up for the first time, its becoming visible when I go to next tab and come back. I would like to see all the items of the listview when its loaded for the first time. Please help me to fix this problem.
This is the xml for the listview -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ListView
android:id="#+id/listview_categories"
android:layout_width="fill_parent"
android:divider="#color/light_gray_a1"
android:dividerHeight="0.667dp"
android:background="#color/white"
android:layout_height="fill_parent" />
</RelativeLayout>
add bottom padding like this and change fill_parent to match_parent
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ListView
android:id="#+id/listview_categories"
android:layout_width="match_parent"
android:divider="#color/light_gray_a1"
android:dividerHeight="0.667dp"
android:paddingBottom="40dp"
android:background="#color/white"
android:layout_height="match_parent" />
</RelativeLayout>
I had this issue. Just now I solved it. Look for android:layout_weight in all the Layouts you used and if it is set some non zero values like android:layout_weight="1" or android:layout_weight="0.91", then set them to zero like this,
android:layout_weight="0"

How to make an ImageView overflows to the Toolbar in Android

I have a Toolbar and some fragments in FrameLayout. However in such a case I am asked to make an ImageView in a fragment which its half will be on the Toolbar. I couldn't figure it out. I considered to cut the image and make it an Options menu item and rest of it will be on the top of the fragment, but I think this won't be very effective for different devices. Can you please help me?
I don't sure what exactly u need.
But if I get it. Here is something u can do.
U just need to make your fragment on whole screen and draw toolbar over fragment.
Here is the snippet. I don't tested it:
your_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Toolbar //name possibly incorrect(change to correct one)
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"/>
</RelativeLayout>
Then inside fragment layout:
fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView //or any other container for your stuff
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="#dimen/toolbar_height"
android:clipToPadding="false"/>
<ImageView //your imageView that will draw halfover toolbar
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/half_toolbar_height"/>
</FrameLayout>
The snippet above possibly won't work correctly. But anyway it can be start point to solve your problem. Good luck!

How to overlap a layout with mapview

Hello everyone I'm developing an app. I want to overlap a layout with map like image show. I added framelayout but when i playing my hand over the framelayout it affect my map. How can i solve this issue ?
Thanks in advance.
PS: No matter context. My xml like this. But my touch on framelayout affect map too.
My Main.XML ;
<RelativeLayout 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"
tools:context=".MainActivity$PlaceholderFragment">
<com.esri.android.map.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.esri.android.map.MapView>
<FrameLayout
android:layout_width="240dp"
android:layout_height="400dp"
android:background="#fcccff"
>
</FrameLayout>
</RelativeLayout>
Inside your Frame layout set this attribute and let me know
<FrameLayout
android:layout_width="240dp"
android:layout_height="400dp"
android:background="#fcccff"
android:setClickable="true"
>
</FrameLayout>

view pager not smooth when embedded within scrollview?

I have requirement like play store app where there is view pager with images and videos
and scroll to view details .Unfortunately when user scrolls the scroll is jumpy but if i remove the scrollview the view pager works perfectly fine .
The layout look and feel is something like this
http://cl.ly/MBRB
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fillViewport="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:background="#drawable/loading_image"
android:gravity="top"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/product_image_pager"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/titles"
style="#style/CirclePageIndicator"
android:layout_alignParentBottom="true"
android:padding="10dip"
android:paddingBottom="10dp" />
</RelativeLayout>
<include layout="#layout/app_screen_menu" />
</LinearLayout>
</ScrollView>
Btw i am loading images from server .
Thanks
You are using 2 scrollisteners
A viewpager uses a scrolllistener
A scrollview uses a scrolllistener
These two scrollistener are fighting for the ScrollEvent.
You can solve this by implementing onInterceptTouch. In this method you can decide who wins the fight over the ScrollEvent
Take a look at this protected post regarding a similair issue containing 2 scrollviews

Categories

Resources