I'm developing a chat application. Recently I changed the Chat, Activity (no lag) to Fragment (so many lag when resizing) because I wanted to build a flexible UI but now there is my problem : When the keyboard show up or disappear the UI resizing is very laggy.
I tried to changed adjustpan and other inside the manifest -> not working
When I remove the recyclerview from de chat -> it works, no lag when the keyboard show up.
So I guess the problem is here (I'm not sure),
I noticed this error RecyclerView: No adapter attached; skipping layout
I tried to fix it with other post on stackoverflow but no success. The error also appears when I scroll the recyclerview or when the keyboard appears.
When I have lot of messages inside my adapter it's very laggy when the view is resizing.
About the architecture
The MainActivity have one container.
the container can contain fragments : FamilyFragment, SettingFragment, RootChatFragment
RootChatFragment -> building flexible UI (Contact Fragment and ChatFragment) or just Contact Fragment if it's mobile view
Can someone help me ? (sorry for my bad english)
Here a screenshot when I close the keyboard.
UPDATED, FIXED
Using android:layout_weight="value" was the problem but I don't know why.
Old one
<?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"
android:padding="20dp"
android:fillViewport="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.myapp.fragments.SpaceContact"
android:id="#+id/contact_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.myapp.fragments.SpaceChat"
android:id="#+id/chat_fragment"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
</RelativeLayout>
New one without lag
<?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"
android:padding="20dp"
android:fillViewport="true">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.myapp.fragments.SpaceContact"
android:id="#+id/contact_fragment"
android:layout_width="350dp"
android:layout_height="match_parent" />
<fragment android:name="com.myapp.fragments.SpaceChat"
android:id="#+id/chat_fragment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/contact_fragment"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</RelativeLayout>
Related
My app and the RecyclerView was working fine until I add the second RecyclerView on to the fragment. Since I added the second fragment, I added a ScrollView to the fragment. Then I faced some issue with the scrolling within the recyclerview, it didn't scroll smoothly. After going through a lot of articles online including StackOverflow, I changed the ScrollView with androidx.core.widget.NestedScrollView. This fixed the issue with scrolling but some major issue occured. The loading of items in the RecyclerView took more time, when I hit the searchbutton, that's there on the menu bar at the top, it took long time to expand the search field and some times app show 'not responding' message. Some articles say add .setNestedScrollingEnabled=false and I added it like the following in onCreateView() of the fragment. But I am still facing the issue.
I am using kotlin
binding.rv_home_items.isNestedScrollingEnabled=false
binding.rv_home_categories.isNestedScrollingEnabled=false
Following is the xml
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorOffWhite"
android:orientation="vertical"
tools:context=".ui.fragments.HomeFragment">
<FrameLayout
android:id="#+id/framelayout_category"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_home_categories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="horizontal"
android:paddingBottom="15dp" />
<ImageButton
android:id="#+id/ibutton_show_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="5dp"
android:background="#drawable/ic_show_category" />
</FrameLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/framelayout_category">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.denzcoskun.imageslider.ImageSlider
android:id="#+id/image_slider"
android:layout_width="match_parent"
android:layout_height="200dp"
android:visibility="gone"
app:iss_auto_cycle="true"
app:iss_corner_radius="5"
app:iss_delay="0"
app:iss_error_image="#color/colorDarkGrey"
app:iss_period="2500"
app:iss_placeholder="#color/colorDarkGrey"
app:iss_selected_dot="#drawable/default_selected_dot"
app:iss_unselected_dot="#drawable/default_unselected_dot"
tools:visibility="visible" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_home_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/image_slider"
android:layout_marginBottom="50dp" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
I am completely stuck on my project, any help with this is highly appreciated
Edit:
When I launch the app, in a few seconds it's shows a message that the app is not responding.
If you have more than one RecyclerView and even all of them have same scroll direction, seems ConcatAdapter can be preferred solution.
ConcatAdapter enables sequentially combine multiple adapters to a single RecyclerView.
I have viewpager2 with 4 fragments. 3 of them have SwipeRefreshLayout to refresh async task data in particular fragments.
When using SwipeRefreshLayout and viewpager2 the gestures are somehow conflicting. ie. swype down to refresh makes screen so sensitive, that a little move to left or right also makes page screen change and refresh icon is freezing or the processis unfinished.
my goal is to make gestures independent, so for example when i start to swype down SwipeRefreshLayout, then vp2 is disabled so it it is not interfere with SRL.
This was not happening when using standard viewpager with SwipeRefreshLayout, gestures were not conflicting, but I need to use "setUserInputEnabled" in VP2. any idea how to mitigate this behaviour and should i mitigate it at SwipeRefreshLayout level or within viepager2 code?
It looks problem is resolved when I added to my scrollview:
android:nestedScrollingEnabled="true"
Final code of the fragment layout then looks like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/some_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/activity_background"
tools:context="some_fragment_name">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:nestedScrollingEnabled="true" <<<<------ HERE the change
android:id="#+id/some_id">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/sensors_relative_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="some_package_name">
<TextView
android:id="#+id/some_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#android:color/white"
android:gravity="center"
android:textColor="#android:color/black"
android:textStyle="bold"
android:layout_marginTop="5sp"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:textSize="20sp" />
...
EDIT: Update as 1.1.0 has been released on July 22, 2020
The problem was due to a bug in SwipeRefreshLayout, which has been resolved by Version 1.1.0. To use it, just upgrade to that version by adding the following line in the dependencies of your Gradle file:
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
See issueTracker for the bug history: [ViewPager2] SwipeRefreshLayout should not ignore requestDisallowInterceptTouchEvent. Note that there's also a workaround described there (extending SwipeRefreshLayout and overriding "requestDisallowInterceptTouchEvent").
If you have RecyclerView in SwipeRefreshLayout you need to wrap RecyclerView in FrameLayout aur any other layout and set nestedScrollingEnabled="true" on Layout not set on RecyclerView.
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/media_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
I have this piece of layout or Android which is problematic:
<?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:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/influencerMainPhotoImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<android.support.v7.widget.RecyclerView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/photos_list"
android:name="com.company.android.InfluencerFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:context="com.company.android.InfluencerFragment"
tools:listitem="#layout/fragment_photo"/>
</LinearLayout>
The problem is that the embedded RecyclerView is doing nested scrolling (ie. it scrolls within itself) - I don't want this.
I'd like to the entire screen to scroll as a single piece.
I tried to set "view.setNestedScrollingEnabled(false);" (on the LinearLayout view) but it says it works only for API 21 and above. My project is set to min API 15.
What can I do to make the entire screen scroll as a single piece?
You can replace View with ViewCompat(v4 compat lib):
https://developer.android.com/reference/android/support/v4/view/ViewCompat.html
where you have the setNestedScrollingEnabled(boolean); method.
While playing around with the Gallery I've got another question (this probably should be simpler).
I'm trying to show a view, lying in front of the Gallery, probably hiding it partially. Like a message dialog (Toast).
In order to do so, I'm using a FrameLayout with a Gallery in the back, and ImageView with a transparent src in the front. When a dialog should be shown, I'm setting the src to the needed drawable through "sendImage".
The problem is, as I assume, that the gallery/list items (that are added dynamically upon "onRequestListItem -> sendListItem") have more recent z-Order (as they have been added later), so the dialog is shown between the background of the Gallery and the transparent icons, representing the list items.
Maybe someone will have an idea, how to avoid this situation?
I am not aware of any way of adding views manually to the layout on the SmartWatch, or changing their zOrder through "bringToFront".
Here is the source code:
gallery.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" >
<Gallery
android:id="#+id/gallery"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/toast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/toast_dialog_message" />
</FrameLayout>
gallery_item.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" >
<ImageView
android:id="#+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20px"
android:src="#drawable/item_icon" />
</RelativeLayout>
GalleryControlExtension.java
sendImage(R.id.spritz_image, drawableResourceId);
P.S. In the emulator it works as expected: toast lies over the item_icon ...
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