TextView实现中间文字两侧图片的样式 和 左侧图片右侧文字
16lz
2021-01-23
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); }}
中间文字,两侧图片 左侧图片(icon)右侧文字,图片距离文字像素20px:
title.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.mall_purchase_left), null, null, null); title.setCompoundDrawablePadding(CoocaaApplication.Div(20));
更多相关文章
- Android 异步加载一张网络图片
- android 使图片显示 圆角
- android ImageUtils 图片处理工具类
- Android 获取SDCard上图片和视频的缩略图
- android 网络图片与网页读取
- Android 利用TransitionDrawable 实现两张图片渐变切换