欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享

程序员文章站 2023-11-16 17:38:34
如果想在自定义的view上面显示button 等view组件需要完成如下任务   1.在自定义view的类中覆盖父类的构造(注意是2个参数的)复制代码 代码如下:  pu...

如果想在自定义的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"

  android:layout_width="fill_parent"

  android:layout_height="fill_parent"

  >

  < com.lovose.myview2

  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>

  //哈哈,你可以任意定义ui的显示了