I am trying to do some task NOT REFRESH when I am pulling a recyclerView, but the problem is it's showing the reload icon. I don't want to show that. I try to hide that in this way:
swipeRefreshLayout.setColorSchemeColors(0,0,0,0);
swipeRefreshLayout.setProgressBackgroundColor(android.R.color.transparent);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
// Refresh items
}
});
But it still showing a round circle with shadow. How can I detect pulling in a recylerview using Swiperefreshlayout (with out progress icon) or any other way?
You'll just need a line of code to do this
SwipeRefreshLayout.setRefreshing(false)
You just need to use swipeRefreshLayout.setRefreshing(false).
See this answer: https://stackoverflow.com/a/30328196/2949612
Use of void setRefreshing (boolean refreshing) :
Whether or not the view should show refresh progress.
Edits:
As per SwipeRefreshLayout doc:
If an activity wishes to show just the progress animation, it should call setRefreshing(true). To disable the gesture and progress animation, call setEnabled(false) on the view.
So you also need to add swiprefreshLayout.setEnabled( false ); after swipeRefreshLayout.setRefreshing(false) line.
Related
I would like to show a custom animation to match the other animations that I have in my RecyclerView. I can’t find a straight forward way of adding custom animations for removal. I know that when RecyclerView replaced ListView one of the talking points was the ability to know when items are added or removed rather than simply saying the dataset has changed and updating everything, so I figured there would be an easy way to add an animation to a View when it is removed that I am missing.
When I add an animation to a view that is removed the animation will not play. This is likely because the View is removed and the animation stops. Is there an easy way to add an animation to a View that doesn’t get cut off? I'm assuming that I could use a second thread, but I want to know if I am missing something.
//code for removal
holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//animation to be added here on view
list.remove(holder.getAdapterPosition());
notifyItemRemoved(position);
notifyItemRangeChanged(position,list.size()-position);
}
});
All add/change/delete/move animations in recyclerView are made by ItemAnimator (by default animator is DefaultItemAnimator). So if you need custom delete animation you should provide custom ItemAnimator via recyclerView.setItemAnimator(animator) method.
I suggest to extend from SimpleItemAnimator and override animateRemove method.
If its possible make Swipe refresh layout animation fully invisible? I want to make whole animation (including loading and cricle with arrow when pulling down gesture) dissapear but I want to be able to use the onRefresh function. Maybe you know any alternatives that I can use in my listview (OnScroll change listener and OverScroll doesnt work for me accroding to trigger the bottom overscoll in my listview and I don wont to trigger my function when the list is swipe up and relase to scroll itself up - the Swipe refresh layout handle it very well for me)
protected void onCreate(Bundle savedInstanceState) {
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
swipeRefreshLayout.setOnRefreshListener(NewActivity.this);
swipeRefreshLayout.setEnabled(false);
swipeRefreshLayout.setRefreshing(false);
}
#Override
public void onRefresh() {
Log.i(TAG, "refresh");
}
Update: According to yours hints I tried to implemented in several ways ( using only setEnabled(false) or setRefreshing(false) or both but in that case the onRefresh function didnt trigger at all.
Use ..
Edited
From the documentation:
If an activity wishes to show just the progress animation, it should call setRefreshing(true). To disable the gesture and progress animation, call setEnabled(false) on the view.
So to show the animation:
swiprefreshLayout.setEnabled( true );
swiperefreshLayout.setRefreshing( true );
And to hide the animation:
swiperefreshLayout.setRefreshing( false );
swiprefreshLayout.setEnabled( false );
When I delete an item from a RecyclerView I want to show a "swipe" animation, that is that the item is moved sideways off the screen. I believe there is support for "swipe to dismiss" using ItemTouchHelper, but this is touch-initiated whereas I want to be able to initiate the swipe programmatically.
I have also tried setting the RecyclerView item animator by extending DefaultItemAnimator. Using this method I can get items to swipe left and right but unfortunately the gap in the list closes quickly such that the swipe does not finish before the list item gap has closed.
Anyone know how to do this?
You can use ItemAnimators offered by this library. More specifically, your would use their SlideInLeftAnimator or SlideInRightAnimator.
Although it's already answered with external library; probably someone wants to do it with raw java.. I have done it with the solution in here
The idea is that, you take off the list item view of the RecyclerView to be deleted and animate it; and normally remove it from the adapter
private void removeListItem(View rowView, final int position) {
Animation anim = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);
anim.setDuration(500);
rowView.startAnimation(anim);
new Handler().postDelayed(new Runnable() {
public void run() {
values.remove(position); //Remove the current content from the array
adapter.notifyDataSetChanged(); //Refresh list
}
}, anim.getDuration());
}
I'm trying to disable the "touch highlight animation" when touching the header. onNavigationItemSelected() is correctly only called when a menu item is touched. But when I touch the header, there is an animation.
I've tried setEnabled(false), setClickable(false) setLongClickable(false), setAnimation(null), setFocusable(false), but it still showing. I cannot find a methods for manipulating the header. (other than addHeader)
Any ideas? Thanks
It seems that updating to the latest version of the design library allowed for the following:
View headerView = LayoutInflater.from(getActivity()).inflate(R.layout.header_view, mNavigationView, false);
headerView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Consume input from header view. This disables the unwanted ripple effect.
}
});
I am quite confident that I tried this without luck before updating, though.
Now I have this problem when:
In my Asynctask, I have a ProgressDialog over this Listview that is constantly updated and scrolling automatically (I use something like mListview.setSelection(mData.size()-1); to scroll it )
I want it to be fullscreen when it's not finished or canceled, which I think is pretty easy by Window dialogWindow = mProgressDialog.getWindow();
dialogWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
I also want it to stop being fullscreen( i.e. I want the status bar shown) when it's finished. And I want the first item in the Listview shown as well.
-------------------- This 's when the problem occurrs.--------------------
I use like
dialogWindow.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
and it's working well. The status bar appears.
then I use mListview.setSelection(0), which I suppose can bring the me first item.
HOWEVER, it has no effect at all. Any idea how this happens or how to solve it? Any help would be greatly appreciated. Thank you!
you can try this method, it maybe helpful to you..
http://developer.android.com/reference/android/widget/ListView.html#smoothScrollToPosition(int)
public void smoothScrollToPosition (int position)
Since: API Level 8
Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
Parameters
position Scroll to this adapter position.
You have to use
mListview.clearFocus();
before calling
mListview.requestFocusFromTouch();
mListview.setSelection(0);
in a post method of mListView.