自定义View
来源:互联网 发布:免费版 ssl 阿里云 编辑:程序博客网 时间:2024/05/23 02:08
//布局
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.bwie.customview"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
package com.example.bwie.customview;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Rect;import android.util.AttributeSet;import android.view.View;import android.widget.LinearLayout;/** * Created by lenovo on 2017/11/5. */public class Custom extends View{ public Custom(Context context) { super(context); } public Custom(Context context, AttributeSet attrs) { super(context, attrs); } public Custom(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onDraw(Canvas canvas) { //自定义画笔 Paint paint= new Paint(); //画笔的大小 paint.setTextSize(10); //画笔颜色 paint.setColor(Color.GREEN); //画布 Rect rect=new Rect(0,0,70,50); //将画布和画笔添加 canvas.drawRect(rect,paint); //自定义画笔 Paint paint1= new Paint(); //画笔的大小 paint.setTextSize(10); //画笔颜色 paint.setColor(Color.RED); //画布 Rect rect1=new Rect(70,50,140,100); //将画布和画笔添加 canvas.drawRect(rect1,paint1); super.onDraw(canvas); }}
阅读全文
0 0
- 自定义view
- 自定义View
- 自定义view
- 自定义View
- 自定义View
- 自定义view
- 自定义View
- 自定义view
- 自定义view
- 自定义View
- 自定义View
- 自定义view
- 自定义view
- 自定义view
- 自定义view
- 自定义view
- 自定义View
- 自定义View
- 【codevs 1200】同余方程
- Fresco+git动画
- 盘点 10 大开源免费的项目管理软件
- Jzoj5454【NOIP2017提高A组冲刺11.5】仔细的检查
- MVP和Fresco和RXJava和绑定取绑加上拉下拉
- 自定义View
- 013 方程组的形式、解的理论、解的结构
- Angular 4入门教程系列:7:Tour Of Heroes之路由
- 二维码扫描
- fresco
- linux基础(五)用户管理、umask、忘记root密码如何解决
- 百度首页
- 扫描二维码
- 爱奇艺首页