Example usage for android.widget HorizontalScrollView scrollTo

List of usage examples for android.widget HorizontalScrollView scrollTo

Introduction

In this page you can find the example usage for android.widget HorizontalScrollView scrollTo.

Prototype

@Override
public void scrollTo(int x, int y) 

Source Link

Document

This version also clamps the scrolling to the bounds of our child.

Usage

From source file:com.facebook.react.views.scroll.ReactHorizontalScrollContainerView.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (mLayoutDirection == LAYOUT_DIRECTION_RTL) {
        // When the layout direction is RTL, we expect Yoga to give us a layout
        // that extends off the screen to the left so we re-center it with left=0
        int newLeft = 0;
        int width = right - left;
        int newRight = newLeft + width;
        setLeft(newLeft);//from  w w w.  ja v a 2s  .c  o  m
        setRight(newRight);

        // Call with the present values in order to re-layout if necessary
        HorizontalScrollView parent = (HorizontalScrollView) getParent();
        // Fix the ScrollX position when using RTL language
        int offsetX = parent.getScrollX() + getWidth() - mCurrentWidth;
        parent.scrollTo(offsetX, parent.getScrollY());
    }
    mCurrentWidth = getWidth();
}

From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java

/**
 * Initialize the activity filling the window with the coins and bills that
 * are inside the moneybox. Also center the coins and bills list to show the
 * middle item.//from   w ww .j ava  2s  .c om
 */
public void initMoneybox() {
    fillMoneybox();

    HorizontalScrollView scroll;
    int offsetX;
    List<CurrencyValueDef> currList;
    int elemWidth;

    currList = CurrencyManager.getCurrencyDefList();
    scroll = (HorizontalScrollView) getActivity().findViewById(R.id.scrollButtonsView);

    elemWidth = currList.get(0).getDrawable().getBounds().right;
    offsetX = ((currList.size() * elemWidth) / 2) - (elemWidth / 2);
    scroll.scrollTo(offsetX, 0);
}

From source file:org.egov.android.view.activity.CreateComplaintActivity.java

/**
 * Function used to show the image added to complaint in image view. A close icon is shown at
 * the top right corner of the image to delete it
 * /*w w w  .j a  v  a2  s .  c  o  m*/
 * @param imagePath
 */
@SuppressLint("InflateParams")
private void _addImageView(String imagePath) {
    final ImageView image_container = (ImageView) findViewById(R.id.image_container);
    LinearLayout container = (LinearLayout) findViewById(R.id.container);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.add_photo, null);

    RelativeLayout inner_container = (RelativeLayout) view.findViewById(R.id.inner_container);
    LinearLayout.LayoutParams inner_container_params = new LinearLayout.LayoutParams(_dpToPix(100),
            _dpToPix(100));

    inner_container.setLayoutParams(inner_container_params);

    ImageView image = (ImageView) view.findViewById(R.id.image);
    image.setImageBitmap(_getBitmapImage(imagePath));
    image.setTag(imagePath);
    container.addView(inner_container);
    imageUrl.add(imagePath);

    image_container.setImageBitmap(_getBitmapImage(imagePath));

    ImageView delete_icon = (ImageView) view.findViewById(R.id.delete_photo);
    delete_icon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            file_upload_limit--;
            RelativeLayout deleteView = (RelativeLayout) v.getParent();
            ((LinearLayout) findViewById(R.id.container)).removeView(deleteView);
            ImageView image = (ImageView) deleteView.findViewById(R.id.image);
            _deleteFile(image.getTag().toString());
            _reorderFiles();
        }
    });
    inner_container.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ImageView image = (ImageView) v.findViewById(R.id.image);
            ((ImageView) findViewById(R.id.image_container))
                    .setImageBitmap(_getBitmapImage(image.getTag().toString()));
        }
    });

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hr_scroll);
            hsv.scrollTo(hsv.getWidth() + 600, 0);
        }
    }, 500);
}

From source file:org.mythtv.client.ui.dvr.GuideTimeslotsFragment.java

private void scrollTimeslot() {

    final HorizontalScrollView hsv = (HorizontalScrollView) getActivity()
            .findViewById(R.id.program_guide_timeslots_scrollview);
    if (null != hsv) {

        hsv.post(new Runnable() {

            /* (non-Javadoc)
             * @see java.lang.Runnable#run()
             *//* w w w.  ja  v  a  2  s .c  o m*/
            @Override
            public void run() {

                final View child = ((LinearLayout) hsv.getChildAt(0)).getChildAt(startingTimeslot);

                Log.v(TAG, "onActivityCreated : scroll to timeslot(" + child.getWidth() + ") "
                        + startingTimeslot + " at postion '" + (startingTimeslot * (child.getWidth())) + "'");
                hsv.scrollTo((startingTimeslot * (child.getWidth())), 0);
            }

        });

    }

}

From source file:org.anurag.file.quest.TaskerActivity.java

/**
 * THIS FUNCTION RESETS THE HORIZONTAL SCROLL VIEW TO START
 * AND DISPLAYS THE APPROPRIATE MESSAGE WHEN MULTI SELECT IS DISABLED
 * @param str/*w ww .  j  a  va  2 s. c om*/
 */
public void MultiModeDisabled(String str) {
    HorizontalScrollView v = (HorizontalScrollView) findViewById(R.id.hscrollView);
    if (CURRENT_ITEM == 3)
        v = (HorizontalScrollView) findViewById(R.id.hscrollView2);
    ImageButton btn = (ImageButton) findViewById(R.id.bottom_multi);
    QuickAction action = new QuickAction(getBaseContext());
    ActionItem item = new ActionItem(1, str);
    action.addActionItem(item);
    v.scrollTo(0, 0);
    action.show(btn);
}