Android自定義View設(shè)定到FrameLayout布局中實(shí)現(xiàn)多組件顯示的方法 分享
如果想在自定義的View上面顯示Button 等View組件需要完成如下任務(wù)
1.在自定義View的類中覆蓋父類的構(gòu)造(注意是2個參數(shù)的)
public class MyView2 extends View{
public MyView2(Context context,AttributeSet att)
{super(context,att);
}
public void onDraw(Canvas c)
{ // 這里繪制你要的內(nèi)容
}
}
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的顯示了
相關(guān)文章
Android Socket實(shí)現(xiàn)多個客戶端即時通信聊天
這篇文章主要為大家詳細(xì)介紹了Android Socket實(shí)現(xiàn)多個客戶端即時通信聊天,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04
Android通過交互實(shí)現(xiàn)貝塞爾曲線的繪制
本篇我們將介紹簡單的交互式繪圖,通過獲取觸控位置來設(shè)定貝塞爾曲線的控制點(diǎn),從而實(shí)現(xiàn)交互式繪制曲線,感興趣的小伙伴可以了解一下2022-05-05
Android Studio3.6新特性之視圖綁定ViewBinding使用指南
這篇文章主要介紹了Android Studio3.6新特性之視圖綁定ViewBinding使用指南,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
Android關(guān)于WebView中無法定位的問題解決
本篇文章主要介紹了Android關(guān)于WebView中無法定位的問題解決,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10
Android ListView長按彈出菜單二種實(shí)現(xiàn)方式示例
這篇文章主要介紹了Android ListView長按彈出菜單的方法,大家參考實(shí)現(xiàn)2013-11-11

