手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享
Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享
摘要:如果想在自定义的View上面显示Button等View组件需要完成如下任务1.在自定义View的类中覆盖父类的构造(注意是2个参数的)复制代...

如果想在自定义的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设定到FrameLayout布局中实现多组件显示的方法 分享】相关文章:

Android实现类似360,QQ管家那样的悬浮窗

Android ListView数据绑定显示的三种解决方法

基于App自适应draw9patch不失真背景的方法详解

Android中实现EditText圆角的方法

解析Android中使用自定义字体的实现方法

Android自定义Custom Dialog对话框

Android开发笔记 TableLayout常用的属性介绍

Android Service中方法使用详细介绍

Android基础之使用Fragment适应不同屏幕和分辨率

Activity透明/半透明效果的设置transparent(两种实现方法)

精品推荐
分类导航