Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hmm, okay, just to point out, when you get to the first or last position (possibly first + 1, last - 1 as well, depending on the button size), you won't be able to have it in the center, as you can't overscroll with just a HorizontalScrollView. With that in mind, for your general case (you can handle the edge cases however you like -- I'd suggest just leaving it scrolled as far as you can, and giving the selected button some sort of highlight) you should be able to do something like this:</p> <pre><code>DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int screenWidth = metrics.widthPixels; //get an instance of your LinearLayout, HSV, and ViewFlipper LinearLayout ll = (LinearLayout)findViewById(R.id.my_linear_layout); ViewFlipper vf = (ViewFlipper)findViewById(R.id.my_view_flipper); HorizontalScrollView hsv = (HorizontalScrollView)findViewById(R.id.my_hsv); //as you've said, there should always be an equal number of Buttons as //Views in the ViewFlipper. This code assumes that is always true. View v = ll.getChildAt(vf.getDisplayedChild()); //assuming smoothScrollTo scrolls to the left side of the screen, //which I think it does, we want to scroll to the Button's center //point, minus (shifted to the right) by half the screen width int scrollTo = v.getLeft() + (v.getWidth() - screenWidth) / 2); //handle overflow for the edge cases if (scrollTo &lt; 0) scrollTo = 0; else if (scrollTo &gt; hsv.getWidth()) scrollTo = hsv.getWidth(); hsv.smoothScrollTo(scrollTo); </code></pre> <p>Untested, and I'm prone to small syntax errors, but the general idea may help. :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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