TextView实现中间文字两侧图片的样式 和 左侧图片右侧文字
16lz
2022-04-22
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(安卓)图片透明度处理代码
- android 根据Bitmap bitmap 保存图片到手机上
- android ImageUtils 图片处理工具类
- Android(安卓)获取SDCard上图片和视频的缩略图
- android 选择图片(从手机照相机或手机图片)
- android ImageUtils 图片处理工具类
- Android(安卓)使用系统摄像头拍相片与拍视频,并显示