I have to implement a smoothScrollToPosition with Eatsy Staggered gridview but the Gridview method doesn't work. How can I do a method that simulate the smooth scroll to a specific cell?
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
if(*myCondition*){
adapter.notifyDataSetChanged();
gridView.smoothScrollToPosition(position);
}
}
}
With standard GridView smoothScrollToPosition works fine, not works with Staggered.
gridView.setSelection(position);
not work correctly, the cells change their position and if I scroll the grid manually restore their correct position (with standard grid view works fine, so I think the problem isn't my code but the library)
Late response but I think you'd be better off using RecyclerView with StaggeredManager: http://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html
Related
I have a TextView that contains a big text and a ScrollView.
So I wanna make a Table of contents for it.
But using the smooth/scrollTo it gives different results on different devices.
I'm trying to achieve scrolling to the same position on different devices.
Thank you.
You can use the position of a widget, for example you can add a widget to any part you want and make it invisible and then get the coordinates of that widget.
scrollView.smoothScrollTo(0,layout_parent.getTop());
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.smoothScrollTo(0,textView.getTop()-100);
}
});
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 am trying to set the fast scroll enabled and visible if there are more items in the list than are currently visible. After setting the adapter, the ListView's count is properly increased but the last visible position is not. As a result I am currently posting a Runnable to wait until the ListView has figured out what items are / aren't visible. The code is as follows:
listView.post(new Runnable(){
#Override
public void run() {
if(listView.getLastVisiblePosition() < (listView.getCount() - 1)){
listView.setFastScrollAlwaysVisible(true);
listView.setFastScrollEnabled(true);
}
}
});
This solution works fine, but feels a bit hackish. Is there a way to know when the last visible position is updated without posting the runnable? Thanks in advance!
I use Chris Banes's PullToRefresh library. PullToRefreshGridview works fine, but there is a problem. When refreshing, the gridview locked, it can't move. I set ptrScrollingWhileRefreshingEnabled as true, the gridview can scroll while refreshing, but the refreshing view is always there, it cannot hide or get smaller like PullToRefreshListview does.
How can I fix it, makes the PullToRefreshGridview works like PullToRefreshListview?
You need to call "onRefreshComplete" method.
for example..
#Override
public void onPullDownToRefresh(PullToRefreshBase refreshView) {
refreshView.onRefreshComplete();
}
I'm trying to recreate ListView (and AbsListView) logic, with view recycling.
I need this but we can say it's only for understand Android logic.
Suppose my children items are the same (same layout), using fixed height RelativeLayout.
During scrolling, I'm reusing ghost children view and set properties for current item.
It's working fine, since I'm using View.offsetTopAndBottom() and invalidate() instead of requesting layout during scroll for optimization.
My problem is updating the children (RelativeLayout).
Depends of item, I want to hide or show ImageView on this item. For that, I'm just using iconImage.setVisibility( GONE ) and iconImage.setVisibility( VISIBLE ).
Since I'm blocking requestLayout, it seems to be setVisibility() does not work properly.
If I use requestLayout, all the tree will measure and layout itself, and it's not a good way for a scrolling user experience.
Is there a way for only request layout on recycle child item ?
You need to notify your listView with changed of view so call notifyDataSetChanged(); from Uithread like this :
final ArrayAdapter adapter = ((ArrayAdapter) getListAdapter());
runOnUiThread(new Runnable() {
#Override
public void run() {
adapter.notifyDataSetChanged();
}
});