How do I make the Checkbox in Android CheckedTextView be left aligned instead of right aligned?

后端 未结 11 2367
悲哀的现实
悲哀的现实 2020-12-09 14:54

I am trying to use R.layout.simple_list_item_multiple_choice with ListView. CheckedTextView is used in simple_list_item_multiple_choice.xml, but how can I make the checkbox

11条回答
  •  独厮守ぢ
    2020-12-09 15:29


    Looking at the source, it's just based on layout direction. Setting it to RTL works well enough for me.

    android:layoutDirection="rtl"
    

    Source:

       private boolean isCheckMarkAtStart() {
        final int gravity = Gravity.getAbsoluteGravity(mCheckMarkGravity, getLayoutDirection());
        final int hgrav = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        return hgrav == Gravity.LEFT;
    }
    

    .

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    
        ...
    
            final boolean checkMarkAtStart = isCheckMarkAtStart();
            final int width = getWidth();
            final int top = y;
            final int bottom = top + height;
            final int left;
            final int right;
            if (checkMarkAtStart) {
                left = mBasePadding;
                right = left + mCheckMarkWidth;
            } else {
                right = width - mBasePadding;
                left = right - mCheckMarkWidth;
            }
            ...
    
            }
        }
    }
    

提交回复
热议问题