I'm using a SwipeRefreshLayout wrapped around a ListView. When the ListView is empty, I've set a TextView to appear. This 'works' fine, but when the ListView is empty and the empty view is showing, the SwipeRefreshLayout doesn't display right. If you drag down, no circle comes down but when you release your finger the circle flashes on the screen and then disappears. If you just touch the screen anywhere, in fact, the SwipeRefreshLayout will appear in the same fashion. The following is how I've defined it in my XML:
<FrameLayout
android:id="#+id/empty_view_requests"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:layout_below="#+id/appbar"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/appbar"
android:id="#+id/buddy_requests_swipe_layout">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buddy_requests_listview"
android:layout_gravity="center_horizontal|top"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_gravity="center_horizontal|center_vertical"
android:id="#+id/norequests_textview"
android:text="No buddy requests."/>
</FrameLayout>
EDIT: Activity Code
swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.buddy_requests_swipe_layout);
swipeRefreshLayout.setColorSchemeResources(R.color.lb_green, R.color.lb_orange, R.color.lb_purple);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
VolleyBuddies.makeGetBuddyRequestsAPICall(BuddyRequestsActivity.this, BuddyRequestsActivity.this);
}
});
FrameLayout noRequestsLayout = (FrameLayout)findViewById(R.id.empty_view_requests);
ListView requestsListView = (ListView)findViewById(R.id.buddy_requests_listview);
requestListAdapter = new BuddyRequestsActivityListAdapter(this, this);
requestsListView.setAdapter(requestListAdapter);
requestsListView.setEmptyView(noRequestsLayout);
How can I fix this?
I am pasting working code of mine.Even I have faced the issues. hope this will works for you.
Initially set the emptyview visibility View.GONE.and then on the API Call response callBacks, if there are no items/statuscode..etc ,setvisibility View.VISIBLE and set it as emptyviewfor listview.
findViewById(R.id.lvemptyview).setVisibility(View.GONE);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
if (Utils.isInternetConnected(getApplicationContext())) {
CallAPICall(lat, lng);
mSwipeRefreshLayout.setRefreshing(false);
} }});
on volley response callback
mSwipeRefreshLayout.setRefreshing(false);
if (statuscode== 200) {
try {
String content = new String(arg2, "UTF-8");
MemberResp memberResp;
Gson gson = new Gson();
Type type = new TypeToken<MemberResp>() {
}.getType();
memberResp = gson.fromJson(content, type);
if (memberResp.Status == 1) {
if (memberResp.bar_lists.size() > 0) {
findViewById(R.id.lvemptyview).setVisibility(View.GONE);
setadapter();
} else {
Adapter.ClearAll();
findViewById(R.id.lvemptyview).setVisibility(View.VISIBLE);
lvList.setEmptyView(findViewById(R.id.lvemptyview));
}
Try placing your TextView inside a ScrollView. I found that the SwipeRefreshLayout requires a scrollable view of some sort
Your code would be
<FrameLayout
android:id="#+id/empty_view_requests"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:layout_below="#+id/appbar"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/appbar"
android:id="#+id/buddy_requests_swipe_layout">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/buddy_requests_listview"
android:layout_gravity="center_horizontal|top"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_gravity="center_horizontal|center_vertical"
android:id="#+id/norequests_textview"
android:text="No buddy requests."/>
</ScrollView>
</FrameLayout>
Should work right away
You have set your parent framelayout as an empty view of the child(listview). Try removing that line.
Empty layout is text view. Please refer following code. and set adapter after SetEmptyListView.
TextView noRequestsLayout = (TextView)findViewById(R.id.norequests_textview);
ListView requestsListView = (ListView)findViewById(R.id.buddy_requests_listview);
requestListAdapter = new BuddyRequestsActivityListAdapter(this, this);
requestsListView.setEmptyView(noRequestsLayout);
requestsListView.setAdapter(requestListAdapter);
Related
I am loading some contents from Firebase and also using FirebaseRecyclerAdapter .
This is the Function which shows data from Firebase successfully :
public void showNotifications() {
databaseReference = FirebaseDatabase.getInstance().getReference("Notifications");
databaseReference.keepSynced(true);
options = new FirebaseRecyclerOptions.Builder<NotificationModel>()
.setQuery(FirebaseDatabase.getInstance().getReference("Notifications"), NotificationModel.class)
.build();
notifRecyclerView.setLayoutManager(new LinearLayoutManager(this));
notificationAdaper = new NotificationAdaper(options, NotificationActivity.this);
notifRecyclerView.setAdapter(notificationAdaper);
checkEmpty(); //will show empty image when recyclerView is empty
}
This is my checkEmpty() method :
private void checkEmpty() {
if (notificationAdaper.getItemCount() == 0) {
Log.e("Item count", String.valueOf(notificationAdaper.getItemCount()));
no_notif.setVisibility(View.VISIBLE);
} else {
no_notif.setVisibility(View.GONE);
}
}
Here is the UI code :
<?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="#android:color/white"
tools:context="com.devapps.NotificationActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:theme="#style/ToolbarTheme">
<TextView
android:id="#+id/toolbarTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Notifications"
android:textColor="#android:color/white"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="visible" />
</androidx.appcompat.widget.Toolbar>
<ImageView
android:id="#+id/no_notif"
android:layout_width="260dp"
android:layout_height="260dp"
android:visibility="gone"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
android:src="#drawable/nonotification" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/notifRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar" />
</RelativeLayout>
The Empty Image Placeholder is always visible even when there is an Item in Firebase Database. How to fix it.
Everytime i am getting E/Item count: 0 even when there is an Item in Firebase Database.
May be you are just altering the visibility of empty view(which you are using to notify user) and not hiding the other views. Like you have recycler view so you need to hide that and view empty message otherwise the message view may be behind the recycler view and hence it is not visible.
Solution
Hide other views on that particular screen
private void checkEmpty() {
if (notificationAdaper.getItemCount() == 0) {
Log.e("Item count", String.valueOf(notificationAdaper.getItemCount()));
no_notif.setVisibility(View.VISIBLE);
notifRecyclerView.setVisibility(View.GONE);
} else {
no_notif.setVisibility(View.GONE);
notifRecyclerView.setVisibility(View.VISIBLE);
}
}
NOTE: notifRecyclerView is the id of recycler view...... I have used it for reference..... if you have declared recycler view with another name in the file , then use that name in lieu of notifRecyclerView
You can use this method to get Recycler View Count
recyclerView.getAdapter().getItemCount();
I am fairly new to android and I am trying to bind a List I have in my ViewModel to a RecyclerView in my UI. I am using Xamarin and MvvmCross. I have the RecyclerView setup like this:
<android.support.design.widget.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:theme="#style/Theme.AppCompat.Light">
<MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView
android:id="#+id/navigation_recycler_view"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:clickable="true"
app:MvxItemTemplate="#layout/menu_item"
app:MvxBind="ItemsSource MyItems"/>
</LinearLayout>
Here's my menu item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="https://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
app:MvxBind="Text Title" />
</LinearLayout>
and lastly, my VM List is something like this:
MyItems = new List<NavItem>
{
new NavItem { Title = "Option1" }
new NavItem { Title = "Option2" }
};
EDIT:
Here where I set the properties:
List<NavItem> _myItems;
public List<NavItem> MyItems
{
get => _myItems;
set => SetProperty(ref _myItems, value);
}
and MyItem:
public string Title { get; set; }
I'm pretty sure it's setup properly; however, for some reason, it won't populate my recycler view. Did I miss something? any help would be very much appreciated. Thanks!
Figured it out! I had xmlns:app="https: instead of xmlns:app="http:
I'm using a Spinner below a title (TextView). It is initially set to View.GONE and when the title is clicked, Spinner is set to View.VISIBLE and the popup window is shown using performClick() below the title, which is what I want.
But I asynchronously update the BaseAdapter to add more items to the Spinner when it is still VISIBLE. After the update the Spinner is moved upwards and is overlaying on the title. How can I fix this?
I have used android:dropDownVerticalOffset, but shows the same behaviour after update.
My layout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/some_other_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#null"
android:overlapAnchor="true"
android:spinnerMode="dropdown"
android:visibility="gone"></android.support.v7.widget.AppCompatSpinner>
</FrameLayout>
</LinearLayout>
Ok.
I Tried running you problem with some slight adjustments on my mobile, and I find no issues.
To simulate your asynchronous addition of items, I added a button.It's OnClick will add items to the adapter.
Next, Instead of extending BaseAdapter, I just used an ArrayAdapter.
And, I just added weights to the LinearLayout to help me with the layout look.
Here Is The Layout :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Title"
android:textSize="20dp"
android:gravity="center"
android:textColor="#android:color/black"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<LinearLayout
android:id="#+id/some_other_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#null"
android:overlapAnchor="true"
android:spinnerMode="dropdown"></android.support.v7.widget.AppCompatSpinner>
</FrameLayout>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Load Adapter"
android:id="#+id/button"
/>
</LinearLayout>
And Here Is the Code for the Activity :
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
}
Spinner spinner;
Button button;
#Override
protected void onResume() {
super.onResume();
spinner = (Spinner) findViewById(R.id.spinner);
button = (Button) findViewById(R.id.button);
List<String> list = new ArrayList<>();
list.add(getRandomStringInRange('A','Z',5));
ArrayAdapter<String> adapter= new ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_item,list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ArrayAdapter<String> adapter = (ArrayAdapter<String>) spinner.getAdapter();
adapter.add(getRandomStringInRange('A','Z',5));
}
});
}
public int getRandomNumberInRange(int lower,int higher){
int range = higher-lower;
range=(int)(range*Math.random());
return lower + range;
}
public String getRandomStringInRange(char lower,char higher,int length){
String str ="";
for(int i=0;i<length;i++)
str+=(char)(getRandomNumberInRange(lower,higher));
return str;
}
}
I did not find the spinner overlapping the title or it moving at all.
It's working fine.
If you want,I'll send you screenshots.
Please tell me if you are facing any other issues
I couldn't really find a solution for this. But solved by setting fixed height for the spinner as mentioned in this solution.
Spinner spinner = (Spinner) findViewById(R.id.spinner);
try {
Field popup = Spinner.class.getDeclaredField("mPopup");
popup.setAccessible(true);
// Get private mPopup member variable and try cast to ListPopupWindow
android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner);
// Set popupWindow height to 500px
popupWindow.setHeight(500);
}
catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
// silently fail...
}
I have searched a lot regarding my query and none of them was useful. I have a recyclerview and some static data inside a scroll view which is inside a root parentlayout as show below.
I have set -
scrollview.scrollto(0,0);
because everytime i open the activity it jumps to the recyclerview firstitem and it skips out the static data above the recyclerview.
recyclerview.setNestedScrollingEnabled(false);
recyclerview.setfocusable(false);
for smoothscroll.
the problem is with-
layoutmanager.scrollToPositionWithOffset(pos,0);
it is not working. I have set the aboveline after setting adapter to recyclerview. Also tried with NestedScrollView but in vain.
although I have used
layoutmanager.scrollToPosition(pos);
For those who skip the code, i have set match_parent to ScrollView and
fillviewport to true.
Here is my layout.
<?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:id="#+id/bottomsheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.inkdrops.khaalijeb.BrandCouponActivity">
<RelativeLayout
android:id="#+id/inclusionviewgroup"
android:layout_width="match_parent"
android:layout_height="match_parent">
<static data/>
<ScrollView
android:id="#+id/scrollviewmain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/one"
android:fillViewport="true"
android:scrollbars="none"
android:layout_above="#+id/donelayout">
<staticdata/>
<TextView
android:id="#+id/dealstext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/card1"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textSize="16sp"
android:text="Deals & Coupons"
android:textColor="#444444" />
<RelativeLayout
android:id="#+id/recyclerlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dealstext"
android:layout_marginTop="5dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#color/colorbackground">
<android.support.v7.widget.RecyclerView
android:id="#+id/coupon_rec_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorbackground"
android:visibility="visible"/>
</RelativeLayout>
<statisdata>
</RelativeLayout>
</ScrollView>
include layout="#layout/activity_coupons"
android:visibility="gone"
/>
</RelativeLayout>
</RelativeLayout>
Need to scroll ScrollView by getting top position of RecyclerView's child :
float y = recyclerView.getY() + recyclerView.getChildAt(selectedPosition).getY();
scrollView.smoothScrollTo(0, (int) y);
you can use scroll view method to reach your desired locations as:
scrollView.smoothScrollTo(int x, int y);
Step 1: Add this line for selecting that position in the recyclerview
adaptercat.setSelectedItem(Integer.parseInt(dealtypeid));
Step 2: Once check below constructor by getting current position
public CatgerotyAdapter(Context context, ArrayList<HashMap<String, String>> arraylist,String selectedPosition) {
this.context = context;
this.data = arraylist;
resultp = new HashMap<>();
currentItemPos=Integer.parseInt(selectedPosition)-1;
}
Step 3: And this function also in adapter
public void setCurrentItem(int item)
{
this.currentItemPos = item;
}
Last step 4. Add this function outside adapter in your class
private void onPagerItemClick2(Integer tag)
{
adaptercat.setCurrentItem(tag);
catsp.setAdapter(adaptercat);
}
Pust this line in your listview item click listner
((ClassName) context).onPagerItemClick2(position);
That position will be selected when will you open listview ..
Use this method scrollToPosition (int position) this is work for me. hope this will help you.
mMessagesRecyclerView = (RecyclerView) findViewById(R.id.messagesRecyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setStackFromEnd(true);
mMessagesRecyclerView.setLayoutManager(layoutManager);
mMessagesAdapter = new MessagesAdapter();
mMessagesRecyclerView.setAdapter(mMessagesAdapter);
mMessagesRecyclerView.scrollToPosition(your position);
this is my layoutstructer
This question already has answers here:
RecyclerView items with big empty space after 23.2.0
(5 answers)
Closed 3 months ago.
I'm making a ToDo list app, and while testing it, for some reason, a huge gap forms between the items whenever I try to scroll down. It always happens whenever I Drag and Drop the items, but I don't see any errors with my ItemTouchHelper adapter and callback class. It would be awesome if you can help me out.
Before:
After:
RecyclerAdapter.java
public class RecyclerAdapter extends
RecyclerView.Adapter<RecyclerAdapter.RecyclerVH> implements ItemTouchHelperAdapter{
private LayoutInflater layoutInflater;
ArrayList<Info> data;
Context context;
public RecyclerAdapter(Context context) {
layoutInflater = LayoutInflater.from(context);
this.context = context;
}
public void setData(ArrayList<Info> data) {
this.data = data;
notifyDataSetChanged();
}
#Override
public RecyclerVH onCreateViewHolder(ViewGroup viewGroup, int position) {
View view = layoutInflater.inflate(R.layout.custom_row, viewGroup, false);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("R.A onClick Owen", "onClick method triggered");
}
});
RecyclerVH recyclerVH = new RecyclerVH(view);
return recyclerVH;
}
#Override
public void onBindViewHolder(RecyclerVH recyclerVH, int position) {
Log.d("RecyclerView", "onBindVH called: " + position);
final Info currentObject = data.get(position);
// Current Info object retrieved for current RecyclerView item - USED FOR DELETE
recyclerVH.listTitle.setText(currentObject.title);
recyclerVH.listContent.setText(currentObject.content);
/*recyclerVH.listTitle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Open new Activity containing note content
Toast.makeText(this, "Opening: " + currentObject.title, Toast.LENGTH_LONG).show();
}
});*/
}
public void deleteItem(int position) {
DBInfo dbInfo = new DBInfo(context);
dbInfo.deleteNote(data.get(position));
// Deletes RV item/position's Info object
data.remove(position);
// Removes Info object at specified position
notifyItemRemoved(position);
// Notifies the RV that item has been removed
}
#Override
public int getItemCount() {
return data.size();
}
// This is where the Swipe and Drag-And-Drog methods come into place
#Override
public boolean onItemMove(int fromPosition, int toPosition) {
// Swapping positions
// ATTEMPT TO UNDERSTAND WHAT IS GOING ON HERE
Collections.swap(data, fromPosition, toPosition);
notifyItemMoved(fromPosition, toPosition);
return true;
}
#Override
public void onItemDismiss(int position) {
// Deleting item from RV and DB
deleteItem(position);
}
class RecyclerVH extends RecyclerView.ViewHolder implements View.OnClickListener{
// OnClickListener is implemented here
// Can also be added at onBindViewHolder above
TextView listTitle, listContent;
public RecyclerVH(View itemView) {
super(itemView);
listTitle = (TextView) itemView.findViewById(R.id.title);
listContent = (TextView) itemView.findViewById(R.id.content);
listTitle.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Toast.makeText(context, "Opening: Note" + getLayoutPosition(), Toast.LENGTH_SHORT).show();
// PS NEVER ADD listTitle VARIABLE AS PUBLIC VARIABLE ABOVE WHICH IS GIVEN VALUE AT ONBINDVH
// THIS IS BECAUSE THE VALUE WILL CHANGE IF ITEM IS ADDED OR DELETED
}
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corners" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.melnykov.fab.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:gravity="bottom|end"
android:onClick="addNote"
android:src="#drawable/fab_ic_add"
fab:fab_colorNormal="#color/colorPrimary"
fab:fab_colorPressed="#color/colorPrimaryDark"
fab:fab_colorRipple="#color/colorPrimaryDark" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
custom_row.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">
<LinearLayout
android:id="#+id/main"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="8dp"
android:text="#string/test"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/main"
android:paddingLeft="8dp">
<TextView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/test"
android:textSize="15sp" />
</LinearLayout>
</RelativeLayout>
Thank you so much to whoever can help me out. I am pulling my hair out as I type.
EDIT: I have confirmed that it is not my ItemTouchHelper class that's the problem. (Tried running without it being called, problem still occurs.)
Also, it seems that when a dialog is shown and the keyboard brought up, the RecyclerView in the background resolves the problem by itself. After dialog is removed, the problem repeats (i.e. Scrolling puts massive space between items)
change in Recycler view match_parent to wrap_content:
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Also change in item layout xml
Make parent layout height match_parent to wrap_content
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
This happened to me many times!
All you need to do is... make layout_height of row file wrap_content and your problem solved..
android:layout_height="wrap_content"
Happy coding!
Its because you are using match_parent in height of root view of the row item in your vertically oriented listview/recyclerview. When you use that the item expands completely wrt to its parent.
Use wrap_content for height when the recyclerview is vertically oriented and for width when it is horizantally oriented.
Avoid taking the view in item layout with a container like this:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceMedium" />
</android.support.constraint.ConstraintLayout>
</layout>
as in this case match_parent will do its work and the problem will still remain! Rather take it like this:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data/>
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceMedium" />
</layout>
[Note: Above code has data binding attached to it, don't use <layout> & <data> tags if not using data binding]
Other than this, if you must use any view group containers, than take a look the height and width attributes in the container, and try change those from match_parent to wrap_content. That should resolve the issue. For more transparency, one can try giving background colours and see through it to identify actual problem.
Just for the record: Since in my case we had to implement some "superfancy UI" with overlapping RecyclerView and blur effect toolbar, I had to get rid of clipToPadding="false" within RecyclerView-xml.
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/height_toolbar"
android:paddingBottom="#dimen/height_bottom_bar_container"
//android:clipToPadding="false" <-- remove this flag!
android:scrollbars="vertical"
/>
paddingTopand paddingBottom worked, but we replaced it with some GapViews(empty views, with height of paddingTop and paddingBottom)
if someone is using | recyclerViewObject.setHasFixedSize(true);
try removing it, It was causing the issue in my case.
You can try setting your Viewgroup holding the recyclerview to wrap content
i have this problem and i just use
android:layout_height="wrap_content"
for parent of every item.