public class StandardView extends LinearLayout {    private Context mContext;    private TextView standard;    private LinearLayout.LayoutParams lp;    private Drawable standardLeftIcon, standardRightIcon;    public StandardView(Context context) {        super(context);        mContext = context;        setBackgroundResource(R.drawable.as_installed_bg);        initView();    }    private void initView() {        standard = new TextView(mContext);        standard.setBackgroundColor(Color.WHITE);        standard.setClickable(true);        standard.setFocusable(true);        standard.setText("蛋蛋扎拉 ");        standard.setGravity(Gravity.CENTER);        standard.setCompoundDrawablePadding(Util.Div(10));//左右图片距离文字的像素        standardLeftIcon = getResources().getDrawable(R.drawable.mall_purchase_left);        standardLeftIcon.setBounds(0, 0, standardLeftIcon.getIntrinsicWidth(), standardLeftIcon.getMinimumHeight()); //必须设置图片大小,否则不显示        standardRightIcon = getResources().getDrawable(R.drawable.mall_purchase_right);        standardRightIcon.setBounds(0, 0, standardRightIcon.getIntrinsicWidth(), standardRightIcon.getMinimumHeight());        standardLeftIcon.setAlpha(255);        standardRightIcon.setAlpha(255);        standard.setCompoundDrawables(standardLeftIcon, null, standardRightIcon, null);        standard.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                standard.setText(" 蛋蛋s扎拉");            }        });        lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, Util.Div(40));        lp.leftMargin = Util.Div(400);        lp.topMargin = Util.Div(400);        addView(standard, lp);    }}
   中间文字,两侧图片
TextView实现中间文字两侧图片的样式 和 左侧图片右侧文字_第1张图片


   左侧图片(icon)右侧文字,图片距离文字像素20px:
  title.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.mall_purchase_left), null, null, null);  title.setCompoundDrawablePadding(CoocaaApplication.Div(20));


更多相关文章

  1. Android 异步加载一张网络图片
  2. android 使图片显示 圆角
  3. android ImageUtils 图片处理工具类
  4. Android 获取SDCard上图片和视频的缩略图
  5. android 网络图片与网页读取
  6. Android 利用TransitionDrawable 实现两张图片渐变切换

随机推荐

  1. android之清理缓存实现
  2. android源码解析--switch
  3. Android Studio 配置SVN 及 代码管理
  4. Android升级SDK提示:folder failed to be
  5. android 图片的缩放,bitmap的用法 scalety
  6. Android代码中运行shell命令
  7. Android(安卓)颜色渲染(九) PorterDuff及
  8. mac 上 配置 Android NDK 环境
  9. android中分割线的实现
  10. Android Canvas drawArc方法介绍