How to make HorizontalScrollView RIGHT to LEFT Scroll android

后端 未结 3 1011
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 06:34

By default HorizontalScrollView scrolls from Left to Right but I want to scroll from Right to Left.

How to do this? Any help will be appreciated.

3条回答
  •  梦毁少年i
    2021-02-20 07:12

    add layout_gravity RIGHT its helpful when items dose not wrap hole with

     
    
                
                
            
    

    and in code need to scroll to the end of list

     findViewById(R.id.scrollPartition).post(new Runnable() {
        @Override
        public void run() {
          ((HorizontalScrollView) findViewById(R.id.scrollPartition)).fullScroll(View.FOCUS_RIGHT);
        }
      });
    

    to set layout_gravity programmatically use this :

        HorizontalScrollView scrollView = new HorizontalScrollView(context);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.RIGHT;
        scrollView.setLayoutParams(layoutParams);
    

提交回复
热议问题