Map Recyclerview Inside Scrollview Display Black Flickering Background While Scrolling
Solution 1:
Write this line in AndroidManifest.xml:
android:hardwareAccelerated="true"
<application
android:name="com.xyz"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
</application>
It works.
Solution 2:
So I dug around a bit, and here are some suggestions to make the performance a little better, it's not perfect, but it is a lot faster.
Map type
This basically determines how the map looks like (normal/hybrid... etc), you need to set the map type to GoogleMap.MAP_TYPE_NONE
in these cases.
XML
where you define the view, so this is the default type- Override
onViewRecycled
in your adapter and if yourholder
has aGoogleMap
set its type to none
Only set your type back to GoogleMap.MAP_TYPE_NORMAL
or whatever type you want, when your onBindViewHolder
is called.
Pre-initialization
Call MapsInitializer.initialize(context)
from your onMapReady
callback.
Initialization
Call GoogleMap.onCreate()
and GoogleMap.getMapAsync()
from your onCreateViewHolder
, maybe in your ViewHolder
constructor.
RecyclerView Prefetch
You can also use a neat new feature of LinearLayoutManager
, you can call LinearLayoutManager.setInitialPrefetchItemCount
, to start preparing off screen items.
Not that this can cause other performance issues, tweak it till you get a nice balance.
Optimize layout
- Try to have the layout where your
RecyclerView
to be flat as possible, don't nest too much layouts - Make sure you set
setHasFixedSize(true)
for yourRecyclerView
- Make sure to avoid weights or
RelativeLayout
s as parents of yourRecyclerView
or your children list items.
Solution 3:
<application
android:name="com.yourpackagename"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Just add hardwareAccelerated as True in your Project Manifest file
Solution 4:
MapView is a pretty heavy view and when you try to get a bunch of them on the screen then app will become sluggish while scrolling. you can pass data such as the latitude and longitude as a string with some static variables taken from the link mentioned below. you can get co-ordinates from the Facebook API. This is the api link https://developers.google.com/maps/documentation/staticmaps/.
String getMapURL = "http://maps.googleapis.com/maps/api/staticmap?zoom=
18&size=560x240&markers=size:mid|color:red|"
+ JOLocation.getString("latitude") + "," + JOLocation.getString("longitude")
+ "&sensor=false";
The above constructed URL, when you used in a browser, returns a .PNG file. Similar type of issue was discussed here in this link MapView in Listview check it. Hope it helps
Post a Comment for "Map Recyclerview Inside Scrollview Display Black Flickering Background While Scrolling"