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

如果想在自定义的view上面显示button 等view组件需要完成如下任务   1.在自定义view的类中覆盖父类的构造(注意是2个参数的)复制代码 代码如下:  pu

如果想在自定义的view上面显示button 等view组件需要完成如下任务

上述就是android开发分享Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享的全部内容,如果对大家有所用处且需要了解更多关于Android学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

  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=”https://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的显示了

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/addevelopment/939225.html

(0)
上一篇 2021年11月13日
下一篇 2021年11月13日

精彩推荐