One solution would be to make your own HorizontalScrollView class and show ImageViews based on scrolling (although I have not tested how much the code below works). Your layout will look like this:
//... <RelativeLayout android:id="@+id/rl_tabs" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:id="@+id/arrow_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/i_button" android:layout_alignParentLeft="true" android:visibility="gone"/> <ImageView android:id="@+id/arrow_Right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/i_button" android:layout_alignParentRight="true" /> <com.your.package.here.SpecialScroll android:id="@+id/my_scrollView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:fillViewport="true" android:scrollbars="none" > <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:tabStripEnabled="true"/> </com.your.package.here.SpecialScroll> </RelativeLayout> //...
The SpecialScroll class will look like this:
public class SpecialScroll extends HorizontalScrollView { public interface PositionListener { public void onLeftArrowRequired(boolean required); public void onRightArrowRequired(boolean required); public View implementScrolledView(); } private PositionListener listener; public void setPositionListener(PositionListener listener) { this.listener = listener; } public SpecialScroll(Context context) { super(context); } public SpecialScroll(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public SpecialScroll(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (l == 0) { listener.onLeftArrowRequired(false); } else { listener.onLeftArrowRequired(true); } View v = listener.implementScrolledView(); Rect r = new Rect(); v.getDrawingRect(r); if ((r.width() - l) == getWidth()) { listener.onRightArrowRequired(false); } else { listener.onRightArrowRequired(true); } } }
Then in your onCreate activity you will do:
SpecialScroll hsv = (SpecialScroll) findViewById(R.id.my_scrollView); hsv.setPositionListener(this);
and implementation of the activity of the PositionListener interface:
@Override public void onLeftArrowRequired(boolean required) { if (required) { ((ImageView) findViewById(R.id.arrow_left)) .setVisibility(View.VISIBLE); } else { ((ImageView) findViewById(R.id.arrow_left)) .setVisibility(View.GONE); } } @Override public void onRightArrowRequired(boolean required) { if (required) { ((ImageView) findViewById(R.id.arrow_right)) .setVisibility(View.VISIBLE); } else { ((ImageView) findViewById(R.id.arrow_right)) .setVisibility(View.GONE); } } @Override public View implementScrolledView() { return findViewById(android.R.id.tabs); }
source share