Android自定義View設定到FrameLayout布局中實現(xiàn)多組件顯示的方法 分享
如果想在自定義的View上面顯示Button 等View組件需要完成如下任務
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的顯示了
相關文章
Android Socket實現(xiàn)多個客戶端即時通信聊天
這篇文章主要為大家詳細介紹了Android Socket實現(xiàn)多個客戶端即時通信聊天,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04
Android Studio3.6新特性之視圖綁定ViewBinding使用指南
這篇文章主要介紹了Android Studio3.6新特性之視圖綁定ViewBinding使用指南,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
Android ListView長按彈出菜單二種實現(xiàn)方式示例
這篇文章主要介紹了Android ListView長按彈出菜單的方法,大家參考實現(xiàn)2013-11-11

