`

Android开发中自定义View设定到FrameLayout布局中实现多组件显示

 
阅读更多

在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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics