首页 > 资料 > 电脑实现多组件显示的代码方法

电脑实现多组件显示的代码方法

发布于:2020-11-02 14:43:58 作者:

电脑实现多组件显示的代码方法

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

二维码

扫一扫关注我们

版权声明:本文内容由互联网用户自发贡献,本站不拥有所有权,不承担相关法律责任。如果发现本站有涉嫌抄袭的内容,欢迎发送邮件至 baisebaisebaise@yeah.net举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

标签: 电脑

相关文章

评论

发表评论