I have created calendar by using recycle view. It worked perfectly in emulator but in real device only few elements gets loaded.
I used horizontal scrollview so all elements load at once and I'm adding padding at both sides for animations.
Code Snippet:
<HorizontalScrollView
android:id="#+id/dateHSV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:scrollbars="none">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/dateRV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:listitem="#layout/rv_item_calender" />
</HorizontalScrollView>
In Mobile
In Emulator (android 6)
As You can see in mobile only 3 dates gets loaded while in emulator (android 6) all dates gets loaded.
Related
I have a horizontal Recyclerview with 2 elements
I would like to call a function to load into a data list when I scroll through the elements of the recyclerview.
I would like to load the data of the item located in the center of the screen / Recyclerview
I am trying with onScrolled but I cannot figure out when in the Recyclerview I change the item
the elements could perhaps become even more than 2 (for example 6) so if it were possible I would like a function that is not necessarily only for 2 elements
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/list_compte"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:divider="#drawable/rectangle_border_bottom"
android:paddingLeft="110dp"
android:paddingRight="110dp"
android:clipToPadding="false"
android:dividerHeight="1dp"
android:isScrollContainer="false"
android:nestedScrollingEnabled="true"
android:orientation="horizontal" />
it's possible?
Thanks
Yes, it is possible. There is a good tutorial here by Nick Rout which perfectly describes your case.
I have been given the task to implement a feature on Mobile application. Previously I had no experience with Android nor Java.
What I need is one screen (one fragment) to display two lists of events with uneven number of members one after another, let's call them ListX and ListY.
I've made layout containing two RecyclerViews and two labels (one label to act as header for each of recycler views).
It is working as it is now and I have events displayed, but ListX is scrollable even though its layout_height is set to wrap_content (only 6 items displayed at the time) while ListY is not scrollable and is displaying all events in collection.
What I need is all items from ListX displayed in first RecyclerView (without scroll), and after that ListY displayed in second RecyclerView without scroll too.
Layout:
<FrameLayout
android:id="#+id/resultsView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/label_daily" />
<android.support.v7.widget.RecyclerView
android:id="#+id/list_daily"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/label_daily"
tools:listitem="#layout/fragment_timetracking_event_item" />
<TextView
android:id="#+id/label_unfinished" />
<android.support.v7.widget.RecyclerView
android:id="#+id/list_unfinished"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/label_unfinished"
tools:listitem="#layout/fragment_timetracking_event_item" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
As you can see from XML both RecyclerViews have layout_height set to wrap_content yet first RecyclerView is not obeying.
Here is sketch of how it should look like
Is there any way to put both lists in one RecyclerView and make custom separators? Or any other way to anchor beginning of one list to the end of the other and make them show all items without scroll?
I hope to get help here.
You don't need 2 recyclerViews, you can achieve using single recylcerView.
You should read about getItemViewType & using same in bindViewHolder & createViewHolder
You can specify these three types
Header
DailyItem
FinishItem
Create your list like this
add Daily HEADER
add Daily ITEMS
add Unfinished HEADER
add Unfinished ITEMS
Now you can render both lists in single recyclerview
Your problem
...other way to anchor beginning of one list to the end of the other and make them show all items without scroll?
has a simple solution without rewriting your code to the one RecycleView - just put android.support.v4.widget.NestedScrollView instead of ScrollView in your xml layout. It seems to be a bug in the ScrollView widget, which is fixed in android.support.v4.widget.NestedScrollView.
P.S. After solving this problem you will face with other problem - Android RecycleView scrolls with no momentum, which is resolved in "RecyclerView within NestedScrollView Scrolling Issue". It is fine only for short item list in RecycleView because as it is mentioned in comments to above article
This is not a good solution since disabling nested scrolling will disable cell reuse as well, therefore loading all cells at once.
which will have impact on the memory consumption of your app in the case of long item list.
I have a View like below
<ScrollView android:id="#+id/appsgridscroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fadeScrollbars="true"
android:scrollbarFadeDuration="10000"
android:layout_below="#id/applisttitlebar">
<LinearLayout android:id="#+id/appsgridlayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
And I am dynamically adding GridViews to the Linearlayout.
I am running with below issue.
The GridView does not stretch to fill its content (As you see the image show only first row when it have more items in GridView)
The GridView does not scroll (it show the scroll bars - see image) on Phone (Android 4.1.2) but scroll on Nexus7 (7inch tablet)
Any ideas?? Please suggest.
GridView already has a scrollbar, so there is nothing that you need to do. In Android 2.2, the bar will only appear by default when the user is actively swiping the grid. There are a series of attributes defined on the View class you can use to tailor the behavior of the scrollbar.
#CommonsWare
I'm developing an app which contains an image at the upper half of the screen and a gridview in the half below, like this:
<de.test.gridview.Image
android:id="#+id/image_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fadingEdgeLength="0dp"
android:scrollbars="none"
android:visibility="gone" />
<de.test.gridview.DraggableGridView
android:id="#+id/grid_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/topnews_container"
android:background="#FFF"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="none"
android:tag="grid_view_tag" >
</de.test.gridview.DraggableGridView>
The Image is set to visibility=gone and set to visible in the code manually later on.
When I now drag on of the childs of the gridview I cant be able to drag them over the image in the upper half of the screen. They are always behind the image, but never in front of it. I've tried to use
gridView.bringToFront()
and also within the gridView I tried this function. I also tried this on the children of the gridview with gridView.bringChildToFront(child). But nothing worked.
Does anybody have an idea?
I guess view with property set to View.GONE is not operational via bringToFront(). So I believe the following will work (if you are trying to bring the grid to the front/top of z):
gridView.setVisibility(View.INVISIBLE);
gridView.bringToFront();
But its looks like you want to bring imageView to the front (making gridView behind instead of front). If so you need to:
imageView.setVisibility(View.INVISIBLE);
imageView.bringToFront();
Android does not have a support for section headers on ListView by default. Based from my research, I've learned that there are 2 ways to implement a section header on ListView. The first one is to support 2 types of views in the list view: the separator view and the content view. The second one is to include a separator view in all of the content views and just set the visibility of the separator view to either VISIBLE or GONE. I'm using the second method.
However, when I scroll the ListView upwards, the section header is also scrolled up. I know this is normal. But I want the section header to remain on top as long as some data belonging to its section are still being displayed. The behavior that I want to accomplish is similar to the behavior of the section headers of UITableView in iOS. How can I accomplish this?
Also, I would like to note that I've read that one solution for this is to create a view above the ListView and just change it if needed. However, this won't work for all phones. For example, the ListView on Samsung phones are bouncing. If I placed a view above the ListView to act as header and the ListView bounces, the dummy header view won't bounce together with the ListView. Also, the top of the default ListView can easily be spotted because it glows when the ListView is being scrolled. Is there anyway to accomplish the said effect while making sure that it still looks natural?
The picture below shows the problem that I will be encountering if I just add a textview on top of the listview: (Taken from Samsung Galaxy S2)
see in this xml + symbol is static u will get some help
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearlayout">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#00ffff">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/plus" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>