public class LeafView extends View {
private String TAG = "--------LeafView";
public LeafView(Context context, AttributeSet attrs) {
super(context, attrs);
Log.i(TAG, "我是自定义View: LeafView");
}
}
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:background="@color/colorPrimary"
>
<com.my.LeafView
android:id="@+id/leafView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
public class MyView extends View {
private String TAG = "--------MyView";
private int width, height;
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
width = w;
height = h;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Rect rect = new Rect(0, 0, width, height);
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawRect(rect, paint);
}
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Rect rect = new Rect(0, 0, width, height);
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawRect(rect, paint);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有