让我们一起爱米兰
站内搜搜:
移动设备
请扫描二维码
或访问
m.milan100.com
您所在的位置 -> 米兰百分百 -> android相关 -> android 自定义View

android 自定义View

点击数:1706 发表时间:2011-02-22 22:57:09 作者: 来源链接:
分享到:
分享到微信

1.首先你写的view要继承view 在自定义View的类中覆盖父类的构造(注意是2个参数的)

public class MyView2 extends View{

  public MyView2(Context context,AttributeSet att)
{super(context,att); 
}
  public void onDraw(Canvas c)
  { // 这里绘制你要的内容

  }
}

2.定义布局文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >

<com.lovose.MyView2  // 这里引用你的view要完整的路径名哦!
android:id="@+id/View01" 
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
>
</com.lovose.MyView2>

<AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:text="Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="100dip" android:layout_y="100dip"></Button>


</AbsoluteLayout>
</FrameLayout>

0
很 好
0
一 般
0
差 劲
热门新闻
相关文章
上一篇: Android自定义View中的事件
下一篇: adb工具的使用
评论区
匿名

返回首页 | 收藏本页 | 回到顶部
Copyright 2010. 米兰百分百 Powered By Bridge.
京ICP备15050557号