最近很多朋友喜欢上设计,但是大家却不知道如何去做,别担心有图老师给你解答,史上最全最棒的详细解说让你一看就懂。
【 tulaoshi.com - 编程语言 】
如果想在自定义的View上面显示Button 等View组件需要完成如下任务
1.在自定义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"
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)android:layout_width="fill_parent"
android:layout_height="fill_parent"
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
com.lovose.MyView2
android:id="@+id/View01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
/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
//哈哈,你可以任意定义UI的显示了
来源:http://www.tulaoshi.com/n/20160219/1591860.html
看过《Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享》的人还看了以下文章 更多>>