Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享

宝贝兔119

宝贝兔119

2016-02-19 09:43

最近很多朋友喜欢上设计,但是大家却不知道如何去做,别担心有图老师给你解答,史上最全最棒的详细解说让你一看就懂。

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

  1.在自定义View的类中覆盖父类的构造(注意是2个参数的)
代码如下:

  public class MyView2 extends View{

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

  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"

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

  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的显示了

展开更多 50%)
分享

猜你喜欢

Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享

编程语言 网络编程
Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享

Android 自定义View的使用介绍

编程语言 网络编程
Android 自定义View的使用介绍

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Android自定义格式显示Button的布局思路

编程语言 网络编程
Android自定义格式显示Button的布局思路

IOS实现自定义布局瀑布流

编程语言 网络编程
IOS实现自定义布局瀑布流

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

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

编程语言 网络编程
解析Android中使用自定义字体的实现方法

解析在Android中为TextView增加自定义HTML标签的实现方法

编程语言 网络编程
解析在Android中为TextView增加自定义HTML标签的实现方法

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

删除重复记录并且剩下一条

删除重复记录并且剩下一条

ASP 类专题

ASP 类专题
下拉加载更多内容 ↓