android


gaps between item in recyclerview increasing while list updating dynamically and repeatedly android


i am showing a list coming from server with recyclerview,request to update list executing after certain time and if new item, it will be added to the list but after every request executing gaps between items in recyclerview getting large.
my xml code to show recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/content_notification_list_show"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.systechdigital.webadeal.NotificationListShowActivity"
tools:showIn="#layout/activity_notification_list_show"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recyclerViewId"
android:background="#c2bfbf"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:adjustViewBounds="true"
>
</android.support.v7.widget.RecyclerView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/emptyViewTvId"
android:text="There is no notification"
android:textSize="23sp"
android:gravity="center"
/>
</LinearLayout>
recyclerview adapter code:
<?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="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.2"
android:layout_marginRight="5dp"
>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/image_notificatoinListShowId"
android:layout_margin="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/proNameTvId"
android:layout_toEndOf="#+id/image_notificatoinListShowId"
android:layout_marginLeft="10dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/notificationMsgTvId"
android:layout_toEndOf="#+id/proNameTvId"
android:layout_marginLeft="7dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/notificationTimeTvId"
android:layout_below="#+id/notificationMsgTvId"
android:layout_marginLeft="10dp"
android:textColor="#000000"
android:layout_marginTop="7dp"
android:layout_toEndOf="#id/image_notificatoinListShowId"
android:layout_marginBottom="5dp"
/>
</RelativeLayout>
<Button
android:layout_width="15dp"
android:layout_height="15dp"
android:id="#+id/circleButtonId"
android:background="#drawable/circle_notification"
android:layout_gravity="center"
android:layout_marginRight="5dp"
/>
</LinearLayout>
adapter java code:
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
NotificationClass notificationClass=notificationClassArrayList.get(position);
Picasso.with(context).load(notificationClass.getProfile_pic_id()).transform(new CircleTransform()).into(holder.image_notificatoinListShow);
holder.proNameTv.setText(notificationClass.getFirst_name()+" "+ notificationClass.getLast_name());
holder.notificationMsgTvId.setText(notificationClass.getActionText());
if(notificationClass.getIsViewed().contains("0")){
holder.circleButton.setVisibility(View.VISIBLE);
}else {
holder.circleButton.setVisibility(View.INVISIBLE);
}
Timestamp timestamp = new Timestamp(Long.valueOf(notificationClass.getLastModify())*1000);
holder.notificationTimeTvId.setText(timestamp.toString());
}
list show java code activity:
notificationListShowAdapter = new NotificationListShowAdapter(recyclerView.getContext(), list);
LinearLayoutManager layoutManager = new LinearLayoutManager(contextNotificationActivity);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(notificationListShowAdapter);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(contextNotificationActivity,
layoutManager.getOrientation());
recyclerView.addItemDecoration(dividerItemDecoration);
notificationListShowAdapter.notifyDataSetChanged();
I would recommend giving fixed height to the notificationMsgTvId and then running the code again. The wrap_content inside list elements are a pain sometimes.
Could you also try giving a color as background to notificationMsgTvId and check if that is the view that is becoming larger?
Also, I would recommend adding a view with grey background at the end of layout as divider instead of using a DividerItemDecoration :)
Try these steps and let me know if the issue still exists. Most of the times, this should solve the above issue.
Cheers!
something is wrong in your layout weight sum.!
<?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="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.0"
android:layout_marginRight="5dp"
>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/image_notificatoinListShowId"
android:layout_margin="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/proNameTvId"
android:layout_toEndOf="#+id/image_notificatoinListShowId"
android:layout_marginLeft="10dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/notificationMsgTvId"
android:layout_toEndOf="#+id/proNameTvId"
android:layout_marginLeft="7dp"
android:textColor="#000000"
android:layout_marginTop="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/notificationTimeTvId"
android:layout_below="#+id/notificationMsgTvId"
android:layout_marginLeft="10dp"
android:textColor="#000000"
android:layout_marginTop="7dp"
android:layout_toEndOf="#id/image_notificatoinListShowId"
android:layout_marginBottom="5dp"
/>
</RelativeLayout>
<Button
android:layout_width="15dp"
android:layout_height="15dp"
android:id="#+id/circleButtonId"
android:background="#drawable/circle_notification"
android:layout_gravity="center"
android:layout_marginRight="5dp"
/>
</LinearLayout>

Related Links

How to animate a wide image (right to left) as the background of my activity?
Android Studio signed apk
Android studio 2.2.2 jitpack dependency url not synced and getting depends on one or more Android Libraries but is a jar
import java classes into Android Studio
Import or use Android Studio projects in Codenvy IDE
Could not execute method for android:onClick - retrofit
Android: Memory Leak
How to add two TextView inside ToolBar
How do I stop music from playing in the background? (react-native-sound)
Load layout created by user
Android with OpenMP
Call log don't update after macking call
How to get Color Depth and Bit Depth from an Image Android
Camera Preview Android
Retrofit #Body POST
Scrolling textview is not scrolling, in Android.

Categories

HOME
fabricjs
api
jpa
spark-streaming
c++11
gpu
redux-form
alexa-skills-kit
jax-rs
ns-3
data-visualization
jax-ws
character
p2p
heap
pega
datastage
job-scheduling
vuejs
charles
ksh
easeljs
monit
displaytag
windows-server-2003
data.stackexchange.com
delimiter
datastax-enterprise-graph
alm
aws-codecommit
laravel-eloquent
simplecv
android-sugarorm
sammy.js
android-maps-extensions
vue-chartjs
slacktextviewcontroller
numpy-broadcasting
apic
connection-pool
recurrent-neural-network
jvmti
mcustomscrollbar
preloader
print-css
claims
oracle-service-bus
angular-http
apache-spark-dataset
dapper-simplecrud
httr
ntvs
proget
zenhub
excel-dna
swingworker
rxtx
rocks
seek
segment-io
wso2developerstudio
expectations
bizagi
nio2
user-management
concept-insights
gocql
rewrite
video-player
phonertc
coda
iced-coffeescript
dnssec
alloy-ui
mruby
punycode
entry-point
unix-socket
cuba
vsx
mysql-error-1044
hidapi
actiondispatch
nokia-s40
thttpd
multiplexing
fitbounds
mbeans
cdonts
svk
luajava
ie-compatibility-mode
facebook-iframe
non-clustered-index
eclipse-marketplace
blender-2.49
mathematical-notation
dojo-dnd
technical-debt
information-management

Resources

Encrypt Message