• 在代码中修改TextView的DrawableRight图片


    TextView的xml
    [html] view plain copy
     
    1. <TextView  
    2.                 android:id="@+id/textciew1"  
    3.                 android:layout_width="match_parent"  
    4.                 android:layout_height="wrap_content"  
    5.                 android:background="#000"  
    6.                 android:drawableRight="@drawable/button_nav_down"  
    7.                 android:gravity="center_vertical"  
    8.                 android:paddingLeft="16dp"  
    9.                 android:paddingRight="16dp"  
    10.                 android:text="展开"  
    11.                 android:textColor="#fff"  
    12.                  />  
    在代码中如果要修改drawableRight设置的图片可以使用
    setCompoundDrawables(Drawable left,Drawable top,Drawable right,Drawable bottom)
    Drawable可以通过 Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);得到

    但是API提示,setCompoundDrawables() 调用的时候,Drawable对象必须调用setBounds(int left, int top, int right, int bottom)方法,于是我们加一行代码就可以了

    [java] view plain copy
     
    1. nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());  

    代码合在一起是这样的:
    [java] view plain copy
     
    1. Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);  
    2. nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());  
    3. textview1.setCompoundDrawables(null, null, nav_up, null);  
  • 相关阅读:
    编译环境及编译器介绍
    linux下同步window的firefox
    DPDK pdump抓包说明
    linux TCP协议(1)---连接管理与状态机
    Linux用户态数据发送和接收
    DPDK之内存管理
    linux socket系统调用层
    linux网络栈结构
    DPDK mbuf何时释放回内存池?
    虚拟设备之linux网桥
  • 原文地址:https://www.cnblogs.com/xgjblog/p/5195228.html
Copyright © 2020-2023  润新知