广告
返回顶部
首页 > 资讯 > 移动开发 >Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享
  • 651
分享到

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

view方法framelayoutAndroid 2022-06-06 10:06:09 651人浏览 安东尼
摘要

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

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

您可能感兴趣的文章:Android 自定义View的使用介绍Android自定义View实现广告信息上下滚动效果Android自定义View实现折线图效果Android自定义View实现可以拖拽的GridViewAndroid自定义View基础开发之图片加载进度条Android中ScrollView实现滑动距离监听器的方法android Animation监听器AnimationListener的使用方法)Android控件系列之Button以及Android监听器使用介绍Android实现静态广播监听器的方法Android编程之监听器的实现方法Android编程自定义View时添加自己的监听器示例


--结束END--

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

本文链接: https://www.lsjlt.com/news/27724.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作