Reputation: 57
I'm sure you know Google Play, I have tab bar with more than 5 tabs. So it's scrollable (horizontally), but i need to scroll it programatically just for 20dp so that the user will notice the scroll function as soon as he/she sees it.
is there an easy way to do that?
Upvotes: 0
Views: 626
Reputation: 2719
Try this,
TabWidget tw = (TabWidget) findViewById(android.R.id.your_tab_id);
LinearLayout ll = (LinearLayout) tw.getParent();
HorizontalScrollView hs = new HorizontalScrollView(this);
hs.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT));
ll.addView(hs, 0);
ll.removeView(tw);
hs.addView(tw);
hs.setHorizontalScrollBarEnabled(false);
credits goes to here
Upvotes: 1
Reputation: 13761
I think this is exactly what you're looking for: http://developer.android.com/reference/android/widget/ScrollView.html#smoothScrollTo%28int,%20int%29
As you're using a Horizontal scrolling, you have to specify the 'x' axis to move. Just tune it until you think it's ok.
Upvotes: 0