Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One solution would be to make you own <code>HorizontalScrollView</code> class and show the <code>ImageViews</code> based on the scroll(although I didn't tested that much the code below should work). Your layout will look like this:</p> <pre><code>//... &lt;RelativeLayout android:id="@+id/rl_tabs" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;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"/&gt; &lt;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" /&gt; &lt;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" &gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:tabStripEnabled="true"/&gt; &lt;/com.your.package.here.SpecialScroll&gt; &lt;/RelativeLayout&gt; //... </code></pre> <p>The <code>SpecialScroll</code> class will look like this:</p> <pre><code>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); } } } </code></pre> <p>Then in your activity's <code>onCreate</code> method you'll do:</p> <pre><code>SpecialScroll hsv = (SpecialScroll) findViewById(R.id.my_scrollView); hsv.setPositionListener(this); // I made the activity implement the SpecialScroll.PositionListener interface </code></pre> <p>and the activity's implementation of the <code>PositionListener</code> interface is:</p> <pre><code>@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); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload