今天在调整界面的时候发现一个问题,在我的手机上(Mi4)可以完成正常使用setCompoundDrawable相关的属性方法
在sony的LT26i上这个属性让我蛋疼了
一下是我的修改之前的代码
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_marginLeft="10dp"
android:drawableLeft="@drawable/icon"
android:textSize="14sp" />
然后在程序中去动态设置它的左边的图标,比如
textview.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.recharge_arrow_green, 0);
在一些手机上完全没有问题, 比如在我的mi4上,但是在这个Sony的手机上这句代码就是没用....
后来在网上找了一下该代码无法执行的原因,好像没人遇到过哈,哎,,,然后就开始研究了,果然过了一会
居然被这样试出来了,去掉控件中的默认的
<pre name="code" class="html"> android:drawableLeft="@drawable/icon"
属性,然后在程序中再用
textview.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon_logo, 0);
属性去设置,就ok了
在此记录一下,下次有朋友遇到的时候不用再浪费时间查找了