在Android开发中,如果我们想自定义View视图组件,并实现在FrameLayout布局中多个组件的同时显示呢?
举例来说想在自定义的View上面显示Button 等View组件需要完成如下任务
1.在自定义View的类中覆盖父类的构造(注意是2个参数的)
1
2
3
4
5
6
7
8
9
10
|
public class MyView2 extends View{
public MyView2(Context context,AttributeSet att)
{super(context,att);
}
public void onDraw(Canvas c)
{ // 这里绘制你要的内容
}
}
|
2.定义布局文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?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的显示了
原文作者:sdhjob
原文链接:http://blog.csdn.net/sdhjob/archive/2009/12/25/5074718.aspx
分享到:
相关推荐
Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享,需要的朋友可以参考一下
很好用的一款自定义android自定义FrameLayout布局Demo,可延伸到自定义View,有需要的小伙伴可以下载试下!
自定义FrameLayout实现手势滑动控制各组件的分层显示
最近对自定义控件充满了兴趣,参考网上的视频写了一个流式布局的例子上传到这,和大家交流学习
高仿新浪微博,采用FrameLayout布局的形式来实现下拉刷新。 在原程序的基础上添加了下拉刷新后listview列表内容的更新,更好的模拟刷新后的效果。 程序已在模拟器中测试通过,且效果很好。
Android中帧布局FrameLayout的特点.pdf 学习资料 复习资料 教学资源
本文实例为大家分享了Android自定义View实现跟随手指移动的小兔子,供大家参考,具体内容如下 自定义的View实现跟随手指的小兔子 按前面的例子新创建一个project,再在project中新创建一个module 将需要的背景图和...
ForegroundViews - 类似于 FrameLayout 的支持的前景自定义 View
这篇文章是介绍Android中自定义键盘的一些套路,通过定义一个数字键盘为例,本篇的文章语言是基于Kotlin实现的,如果还没有用或者不熟悉该语言的同学,可以自己补习,我之前也写过入门文章。 效果图 github:源码...
Android Framelayout显示静态和动态的扑克牌 包含Handler 和Timer TimerTask的使用方法
当滑动时:数值显示,滑动停止时显示数字,使用FrameLayout结合SeekBar。 首先我们看看。 Layout: <?xml version=1.0 encoding=utf-8?> <merge xmlns:android=http://schemas.android.com/apk/res/android ...
Android中帧布局FrameLayout的常用属性.pdf 学习资料 复习资料 教学资源
我是刚刚学习的新手,刚学习完成了用FrameLayout布局完成霓虹灯效果的小程序,与大家分享一下。
Android中使用FrameLayout布局完成教学案例的代码清单.pdf 学习资料 复习资料 教学资源
Android中使用FrameLayout布局完成教学案例的要求说明.pdf 学习资料 复习资料 教学资源
FrameLayout(帧布局)实现闪烁霓虹灯效果
Android中常用的5大布局方式有以下几种:...线性布局是Android开发中最常见的一种布局方式,它是按照垂直或者水平方向来布局,通过“android:orientation”属性可以设置线性布局的方向。属性值有垂直(vertical)和水平
LinearLayout 线性布局 控制组件 横向 或者 纵向 排列 RelativeLayout 相对布局 子组件的位置总是相对兄弟...AbsoluteLayout 绝对布局 组件位置通过x, y坐标来控制, 布局容器不再管理组件位置, 大小, 这些都可以自定义;
android demo,FrameLayout的使用,该实例实现了一个美女在地图上的行走。
主要介绍了Android布局之FrameLayout帧布局的相关资料,需要的朋友可以参考下