当前位置: 移动技术网 > IT编程>移动开发>Android > Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

绵贯真弓,雷顿教授与恶魔之箱,花都十二钗

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网