seekBar.setThumb之后导致thumb变小的原因

由于要实现下述的效果:

通过以下方法:

方法1:

Bitmap bitmap = BitmapUtil.drawIndexOnBitmap(R.drawable.activity_seek_bar_thumb, "1");
		mOldThumbDrable =  new BitmapDrawable(bitmap);
	    mSeekBar.setThumb(mOldThumbDrable);
		mSeekBar.setThumbOffset(0);
对thumb进行重新设置时,出现了如下效果:


发现在代码中进行上诉设置与在xml中进行设置时,thumb的大小显示差别很大:

方法2:

xml布局

<SeekBar
            android:id="@+id/seek_bar"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:maxHeight="15dip"
            android:minHeight="15dip"
            android:paddingLeft="5dip"
            android:paddingRight="5dip"
            android:layout_gravity="center_vertical"
            android:progressDrawable="@drawable/activity_page_center_line"
            android:thumbOffset="0dip"
            android:thumb="@drawable/activity_seek_bar_thumb"/>

方法3:

然后我又尝试用下述的代码进行设置:

mOldThumbDrable =getResources().getDrawable(R.drawable.activity_seek_bar_thumb);
 mSeekBar.setThumb(mOldThumbDrable);
结果发现显示正常,和在xml中的布局一样
为什么2,3的能显示正常,1显示那么小?

我下来调试了

drawIndexOnBitmap

方法,发现一下截图:

调试前的drawable:


调试后的:


注意红色的地方,发现尺寸大小变化了,而且应该和Density有关,所以查看了方法1中的

 /**
     * Create drawable from a bitmap, not dealing with density.
     * @deprecated Use {@link #BitmapDrawable(Resources, Bitmap)} to ensure
     * that the drawable has correctly set its target density.
     */
    @Deprecated
    public BitmapDrawable(Bitmap bitmap) {
        this(new BitmapState(bitmap), null);
    }

发现,当在bitmap上画完数字后,通过得到的bitmap构造drawable时,改方法提示了not dealing with density至此,我们找到了原因,所以改用

BitmapDrawable(Resources, Bitmap)
方法即可


结果发现thumb的图标太小,但是

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值