RuffianZhong/RWidgetHelper

RTextView设置icon_with_text图标不居中,点击后居中

scsfwgy opened this issue · 9 comments

image

<com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabTransfer"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="划转"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/wallet_transfer"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple="true" />

Originally posted by @scsfwgy in #46 (comment)

另外,希望可以支持设置icon单边padding值,而不是像原生的 android:drawablePadding="xdp"

@scsfwgy 可以看看你的布局场景吗?我这边模拟了 线性布局,均分三个的情况也是无法复现,可以的话加我QQ(632835821)想知道具体的布局情况,看看是不是需要特殊或者复杂的情况下才能触发

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="80dp"
                android:gravity="center">

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabRecharge"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/Echarge"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/trade_cashin"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    android:layout_marginEnd="12dp" />

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabWithdraw"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/Withdraw"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/trade_cashout"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    android:layout_marginEnd="12dp" />

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabTransfer"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/wallet_header_one2"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/wallet_transfer"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    app:ripple="true" />

            </LinearLayout>

@RuffianZhong

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="80dp"
                android:gravity="center">

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabRecharge"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/Echarge"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/trade_cashin"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    android:layout_marginEnd="12dp" />

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabWithdraw"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/Withdraw"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/trade_cashout"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    android:layout_marginEnd="12dp" />

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabTransfer"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/wallet_header_one2"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/wallet_transfer"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    app:ripple="true" />

            </LinearLayout>

@RuffianZhong

这边测试都是正常的,你把代码缩略,然后看看外面的层级如何?或者你看看能不能尝试定位一下可能是什么问题引起的。我在一个简单页面 上构造你的业务场景是无法复现问题的~

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginTop="80dp"
                android:gravity="center">

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabRecharge"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/Echarge"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/trade_cashin"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    android:layout_marginEnd="12dp" />

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabWithdraw"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/Withdraw"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/trade_cashout"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    android:layout_marginEnd="12dp" />

                <com.ruffian.library.widget.RTextView
                    android:id="@+id/afmwl_rtv_tabTransfer"
                    android:layout_width="0dp"
                    android:layout_height="34dp"
                    android:layout_weight="1"
                    app:border_width_normal="1dp"
                    app:border_color_normal="@color/wrapper_k_divider_design"
                    app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                    android:text="@string/wallet_header_one2"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="@color/white"
                    app:icon_normal_left="@drawable/wallet_transfer"
                    app:icon_width_left="18dp"
                    app:icon_height_left="18dp"
                    app:icon_with_text="true"
                    app:ripple_color="@color/wrapper_k_item_ripper"
                    app:ripple="true" />

            </LinearLayout>

@RuffianZhong

这边测试都是正常的,你把代码缩略,然后看看外面的层级如何?或者你看看能不能尝试定位一下可能是什么问题引起的。我在一个简单页面 上构造你的业务场景是无法复现问题的~

好,我再看看

RTextViewHelper#setIcon(Drawable drawableLeft, Drawable drawableRight, Drawable drawableTop, Drawable drawableBottom) line 815

 //drawable间距
            if (!mDrawableWithText) return;
//这个地方判断==0,所以下面居中的定位失败。
            if (mView.getWidth() == 0 || mView.getHeight() == 0) return;

我是在fragment中使用的

触发场景:默认设置view不可见,页面展示之后通过其他逻辑 设置 RTextView 可见
最新版本已修复

还是有问题:
image

代码:

`

        <LinearLayout
            android:id="@+id/afmwl_ll_topRechargeContainer"
            android:layout_width="match_parent"
            android:layout_height="34dp"
            android:orientation="horizontal"
            android:gravity="center"
            android:layout_gravity="center">

            <com.ruffian.library.widget.RTextView
                android:id="@+id/afmwl_ll_topRechargeItem1"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                app:border_width_normal="1dp"
                app:border_color_normal="@color/wrapper_k_wallet_top_divider"
                app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                app:ripple="true"
                app:ripple_color="@color/wrapper_k_item_ripper"
                app:icon_width_left="15dp"
                app:icon_height_left="15dp"
                android:gravity="center"
                android:textSize="14sp"
                android:textColor="@color/white"
                app:icon_with_text="true"
                android:drawablePadding="6dp"
                android:text="@string/Echarge"
                app:icon_normal_left="@drawable/trade_cashin" />

            <com.ruffian.library.widget.RTextView
                android:id="@+id/afmwl_ll_topRechargeItem2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                app:border_width_normal="1dp"
                app:border_color_normal="@color/wrapper_k_wallet_top_divider"
                app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                app:ripple="true"
                app:ripple_color="@color/wrapper_k_item_ripper"
                app:icon_width_left="15dp"
                app:icon_height_left="15dp"
                android:gravity="center"
                android:textSize="14sp"
                android:textColor="@color/white"
                app:icon_with_text="true"
                android:drawablePadding="6dp"
                app:icon_normal_left="@drawable/trade_cashout"
                android:text="@string/Withdraw"
                android:layout_marginStart="15dp" />


            <com.ruffian.library.widget.RTextView
                android:id="@+id/afmwl_ll_topRechargeItem3"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                app:border_width_normal="1dp"
                app:border_color_normal="@color/wrapper_k_wallet_top_divider"
                app:corner_radius="@dimen/wrapper_k_btn_corners_small"
                app:ripple="true"
                app:ripple_color="@color/wrapper_k_item_ripper"
                app:icon_width_left="15dp"
                app:icon_height_left="15dp"
                android:gravity="center"
                android:textSize="14sp"
                android:textColor="@color/white"
                app:icon_with_text="true"
                android:drawablePadding="6dp"
                app:icon_normal_left="@drawable/wallet_transfer"
                android:text="@string/wallet_header_one2"
                android:layout_marginStart="15dp" />


        </LinearLayout>

`

v1.1.18/v0.0.9 版本已修复