展会信息港展会大全

自定义View设定到FrameLayout布局中实现多组件显示
来源:互联网   发布日期:2016-01-14 09:51:01   浏览:2731次  

导读:在Android开发中,如果我们想自定义View视图组件,并实现在FrameLayout布局中多个组件的同时显示呢?举例来说想在自定义的View上面显示Button 等View组件需要完成如下任务...

在Android开发中,如果我们想自定义View视图组件,并实现在FrameLayout布局中多个组件的同时显示呢?

举例来说想在自定义的View上面显示Button 等View组件需要完成如下任务

[代码] 在自定义View的类中覆盖父类的构造(注意是2个参数的)

01

public class MyView2 extends View{

02

03

public MyView2(Context context,AttributeSet att)

04

{super(context,att);

05

}

06

public void onDraw(Canvas c)

07

{// 这里绘制你要的内容

08

09

}

10

}

[代码] 定义布局文件

01

<?xml version="1.0" encoding="utf-8"?>

02

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

03

android:orientation="vertical"

04

android:layout_width="fill_parent"

05

android:layout_height="fill_parent"

06

>

07

08

<com.lovose.MyView2

09

android:id="@+id/View01"

10

android:layout_width="fill_parent"

11

android:layout_height="fill_parent"

12

>

13

</com.lovose.MyView2>

14

15

<AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_width="wrap_content"android:layout_height="wrap_content">

16

<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>

17

18

19

</AbsoluteLayout>

20

</FrameLayout>

赞助本站

人工智能实验室

相关热词: 自定义 View FrameLayout 布局

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港