2.1.5 自定义view
来源:互联网 发布:mac os 终端命令 编辑:程序博客网 时间:2024/06/02 05:08
自定义view
public class Two_view extends View { private float x = 50; private float y = 50; private Paint paint = null; public Two_view(Context context, @Nullable AttributeSet attrs) { super(context, attrs); //创建画笔 paint = new Paint(); paint.setColor(0xff00ccff); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); /* *绘制一个小球 * 参数分别是 横纵左边 半径 画笔 */ canvas.drawCircle(x, y, 20, paint); } @Override public boolean onTouchEvent(MotionEvent event) { this.x = event.getX(); this.y = event.getY(); this.invalidate(); return true; }}
布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:id="@+id/root" android:layout_height="match_parent"> <com.example.android.two.tool.Two_view android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff"/></LinearLayout>
代码
public class Two extends Activity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.two); }}
页面
阅读全文
0 0
- 2.1.5 自定义view
- Android 自定义View (5)
- Android自定义view(5)
- 自定义view
- 自定义View
- 自定义view
- 自定义View
- 自定义View
- 自定义view
- 自定义View
- 自定义view
- 自定义view
- 自定义View
- 自定义View
- 自定义view
- 自定义view
- 自定义view
- 自定义view
- hello
- 判断是否有网,判断网络连接,跳转至设置
- Linux命令(1)-cat & 反向tac
- mabatis学习之前今日内容介绍 1、final 关键字 2、static 关键字 3、匿名对象 4、内部类 5、包的声明与访问 6、访问修饰符 7、代码块 第一节课 ###01(面向对象)fin
- POJ 3009
- 2.1.5 自定义view
- Ajax和PHP
- 题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前 20 项之和
- SSL2828 2017年11月2日提高组T1 Sequence(kmp)
- 字符串编码(腾讯笔试)
- 关于maven项目导入本地项目生成jar包,一直提示找不到类的处理方法
- bzoj 2109: [Noi2010]Plane 航空管制 贪心+拓扑排序
- Servlet过滤器
- 2017.11.2 支配树上LCA 解题报告