Android开发中自定义View设定到FrameLayout布局中实现多组件显示
2009-12-25 13:19
1146 查看
在Android开发中,如果我们想自定义View视图组件,并实现在FrameLayout布局中多个组件的同时显示呢?
举例来说想在自定义的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的显示了
举例来说想在自定义的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自定义View设定到FrameLayout布局中实现多组件显示
- Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享
- ViewPager嵌套RecycleView(Fragment作为数据源)来展示10条数据,每个Item显示的内容是(Android软件开发工程师)(用自定义的Adapter 实现
- android 让TextView支持的Html标签实现自定义时钟显示组件DigitalClock
- 在Android中,可以自定义类,继承ViewGroup等容器类,以实现自己需要的布局显示。
- Android开发:setContentView切换界面,自定义带CheckBox的ListView显示SQlite条目-----实现
- Android中的自定义View(二)之 流式布局实现
- 【android开发】类抽屉菜单(自定义ViewGroup)的实现
- Android开发之自定义圆形的ImageView的实现
- Android开发中TextView文本过长滚动显示实现方法分析
- Android开发—利用FrameLayout实现图标中间显示文字
- Android开发之ViewPager实现轮播图(轮播广告)效果的自定义View
- Android 自定义View之RadioGroup实现跨多行显示
- android之自定义ViewGroup和自动换行的布局的实现
- android自定义viewgroup实现等分格子布局
- Android自定义组件系列【4】——自定义ViewGroup实现双侧滑动
- Android开发之自定义圆形的ImageView的实现
- Android开发-使用自定义View实现loading效果
- iOS开发进阶 - 自定义UICollectionViewLayout实现瀑布流布局