Hi I want to make Scroll Bar set to Bottom to my Activity on Button Click.
I have try using
final ScrollView Scrbar=(ScrollView)findViewById(R.id.ScrollContainer);
Scrbar.post(new Runnable() {
#Override
public void run(){
Scrbar.fullScroll(ScrollView.FOCUS_DOWN);
}
});
But It's not working the way I want.
How should I'll meet to my requirements?
please suggest
Try
scrollView.post(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getBottom());
}
});
Try to use this: Scrbar.scrollTo(0, Scrbar.getBottom());
Related
How to force a click or touch an item on a recyclerview?
I found people talking to use a command recyclerView.findViewHolderForAdapterPosition(0).itemView.performClick() but recyclerView.findViewHolderForAdapterPosition(0) always returns null!
I want initially that the first recyclerview item is clicked/ touched.
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
recyclerView.findViewHolderForAdapterPosition(position).itemView.performClick();
}
},100);
I am using AndroidSlidingUpPanel on my project . I want to disable sliding on specific condition . So that only top part is visible , and dragging is disabled .
if(condition){
mSlidingLayout.setEnabled(false);
mSlidingLayout.setClickable(false);
}
if the above code doesn't work then try like
if(condition){
runOnUiThread(new Runnable() {
#Override
public void run() {
mSlidingLayout.setEnabled(false);
mSlidingLayout.setClickable(false);
}
});
}
You can use
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
to lock your DrawerLayout so it won't be able to open with gestures. And unlock it with:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
I dont want to scroll it (becz i think it takes time and perfomance to scroll). I want to set it already scrolled to bottom at the start of the activity like whatsapp.
How could this be done?
If you want your ListView to be always scrolled at the bottom even on updating, you can add these attributes to the list:
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
Otherwise use :
listView.setSelection(adapter.getCount() - 1);
listview.setSelection(LastItemIndexInListView);
LastItemIndexInListView : size of listview - 1.
listView.post(new Runnable() {
#Override
public void run() {
listView.scrollTo(0, listView.getBottom());
}
});
Give this a shot.
listView.post(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount() - 1);
}
});
This should work for you
The problem is that I'm using the fullScroll() and scrollTo() functions to scroll but it is animated and I need it happen without user observation.
Is there a way to solve this problem?
hScrollView.post(new Runnable() {
#Override
public void run() {
hScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
});
Use this
// Disable the animation First
hScrollView.setSmoothScrollingEnabled(false);
// Now scroll the view
hScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
// Now enable the animation again if needed
hScrollView.setSmoothScrollingEnabled(true);
You can use hScrollView.setSmoothScrollingEnabled(false); before running the Runnable command, this will give you the desired output
// Set smooth scrolling to false
hScrollView.setSmoothScrollingEnabled(false);
// Then call the fullScroll method
hScrollView.post(new Runnable() {
#Override
public void run() {
hScrollView.fullScroll(View.FOCUS_RIGHT);
}
});
I am using grid view for display images, I want to scroll move automatically, whenever I add another images in gridview, is it possible?
I think you have to read a little bit more :
https://developer.android.com/reference/android/widget/AdapterView.html#setSelection(int)
ListView.setSelection(position);
https://developer.android.com/reference/android/widget/AbsListView.html#smoothScrollToPosition(int)
ListView.smoothScrollToPosition(position).
Either call setSelection() or use smoothScrollToPosition().
I got result using GridView.setSelection(GridView.getCount()),so scroll bar automatically move to last element of Grid View
Use TimerTask to do that since Adapter.notifyDataSetChanged() takes delay to update the grid or list.
Code is below:
new Timer().schedule(new TimerTask()
{
#Override
public void run() {
nameHandler.sendEmptyMessage(0);
}
},500);
//// And in handler::
Handler nameHandler = new Handler()
{
public void handleMessage(Message msg)
{
super.handleMessage(msg);
gridView.setSelection(selectorIndex);
// OR
gridView.smoothScrollToPosition(selectorIndex);
gridView.invalidate();
}
} ;