Android TextView 代码中设置 drawableLeft

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhao2017/article/details/78080418

1.在Android中的xml文件中我们可以轻易的为TextView设置图片,居左,或者居右。

 <TextView
                android:id="@+id/tv_more"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:drawableLeft="@mipmap/icon_right"
                android:drawablePadding="10dp"
                android:text="查看更多"
                android:textColor="@color/black"
                android:textSize="15sp" />

2.在代码中动态的设置,TextView的居左或者居右的图片的方法:

//该处设置的是居左的图片
 tv_more.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.mipmap.icon_down), null, null, null);

猜你喜欢

转载自blog.csdn.net/zhao2017/article/details/78080418