Android, make scrollable view overflow to the left instead of right?

前端 未结 7 2022
孤独总比滥情好
孤独总比滥情好 2021-02-20 00:02

I was recommended using a parent view to get horizontal scrolling right in my TextView:



        
7条回答
  •  你的背包
    2021-02-20 00:09

    Inspired by this

    You can make your own class derived from HorizontalScrollView

    public class RightAlignedHorizontalScrollView extends HorizontalScrollView {
        public RightAlignedHorizontalScrollView(Context context) {
            super(context);
        }
    
        public RightAlignedHorizontalScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public RightAlignedHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            super.onLayout(changed, l, t, r, b);
            scrollTo(getChildAt(0).getMeasuredWidth(), 0);
        }
    }
    

    I posted a complete simple project there

提交回复
热议问题