Android应用开发小知识点
2014-05-13 14:52
323 查看
1- TextView 动态设置粗体
TextView textView = (TextView)findViewById(R.id.textView);
TextPaint tp = textView .getPaint();
tp.setFakeBoldText(true);
2- TextView 动态设置字体大小
setTextSize(int unit, int size)
TypedValue.COMPLEX_UNIT_PX : Pixels
TypedValue.COMPLEX_UNIT_SP : Scaled Pixels
TypedValue.COMPLEX_UNIT_DIP : Device Independent Pixels
3- TextView 边框圆角显示
android:background="@drawable/round_corner"
在drawable目录下,xml文件如下:
4- TextView 放在圆圈里显示
宽和高要相等
在drawable目录下,xml文件如下:
5- ImageView 变圆处理
TextView textView = (TextView)findViewById(R.id.textView);
TextPaint tp = textView .getPaint();
tp.setFakeBoldText(true);
2- TextView 动态设置字体大小
setTextSize(int unit, int size)
TypedValue.COMPLEX_UNIT_PX : Pixels
TypedValue.COMPLEX_UNIT_SP : Scaled Pixels
TypedValue.COMPLEX_UNIT_DIP : Device Independent Pixels
3- TextView 边框圆角显示
android:background="@drawable/round_corner"
在drawable目录下,xml文件如下:
<shape android:shape="rectangle"> <stroke android:color="#d34940" android:width="1dp"/> 边框,颜色 <solid android:color="@color/white"/> 填充颜色 <corners android:radius="30dp"/> 角度 <size android:height="30dp"/> 高度 </shape>
4- TextView 放在圆圈里显示
宽和高要相等
android:layout_width="30dp" android:layout_height="30dp" android:background="@drawable/round"
在drawable目录下,xml文件如下:
<shape android:shape="oval"> <stroke android:color="#d34940" android:width="1dp"/> 边框,颜色 <solid android:color="#00000000"/> 填充颜色 </shape>
5- ImageView 变圆处理
public static Bitmap toRoundBitmap(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float roundPx; float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; if (width <= height) { roundPx = width / 2; left = 0; top = 0; right = width; bottom = width; height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width; } else { roundPx = height / 2; float clip = (width - height) / 2; left = clip; right = width - clip; top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height; } Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect src = new Rect((int) left, (int) top, (int) right,(int) bottom); final Rect dst = new Rect((int) dst_left, (int) dst_top,(int) dst_right, (int) dst_bottom); final RectF rectF = new RectF(dst); paint.setAntiAlias(true);// 设置画笔无锯齿 canvas.drawARGB(0, 0, 0, 0); // 填充整个Canvas // paint.setAlpha(220); paint.setColor(0xFFE24200); // 以下有两种方法画圆,drawRounRect和drawCircle // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);// // 画圆角矩形,第一个参数为图形显示区域,第二个参数和第三个参数分别是水平圆角半径和垂直圆角半径。 canvas.drawCircle(roundPx, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));// 设置两张图片相交时的模式,参考 canvas.drawBitmap(bitmap, src, dst, paint); // 以Mode.SRC_IN模式合并bitmap和已经draw了的Circle return output; }
相关文章推荐
- android Service
- android4.0+版本修改状态栏透明的调试
- Android反汇编教程
- Android string.xml 显示特殊符号
- android 调用系统解锁方法
- android开源项目之OTTO事件总线(二)官方demo解说
- 常见android中的style
- Android中文API(143) —— CountDownTimer
- android ADB命令的使用
- android 唤醒和点亮屏幕
- 系统去掉 Android 4.4.2 的StatusBar和NavigationBar
- android 常用控件 (DatePicker) (TimePicker)
- Android adb 唤醒屏幕 点亮屏幕
- Android 图片加载问题
- android-support关联源码
- android开源项目之OTTO事件总线(一)
- Android Animation 动画Demo
- 开发一个简单实用的android紧急求助软件
- android shape的使用
- Android APK反编译得到Java源代码和资源文件