FrameLayout(帧布局)的基本使用
生活随笔
收集整理的這篇文章主要介紹了
FrameLayout(帧布局)的基本使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
FrameLayout又稱作幀布局,它相比于LinearLayout和RelativeLayout要簡單很多,因為它的應用場景也少了很多。這種布局沒有方便的定位方式,所有的控件都會默認擺放在布局的左上角。
activity_main代碼:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/tv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="This is TextView" /><ImageViewandroid:id="@+id/iv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@mipmap/ic_launcher" /></FrameLayout>效果圖:
可以看到,文字和圖片都是位于布局的左上角。由于ImageView是在TextView之后添加的,因此圖片壓在了文字的上面。
當然除了這種默認效果之外,我們還可以使用android:layout_gravity屬性來指定控件在布局中的對齊方式,這和LinearLayout中的用法是相似的。
修改activity_main.xml中的代碼:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/tv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="left"android:text="This is TextView" /><ImageViewandroid:id="@+id/iv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:src="@mipmap/ic_launcher" /></FrameLayout>效果圖:
總體來講,FrameLayout由于定位的欠缺,導致它的應用場景也比較少,不過之后使用碎片的時候是可以使用到的。
?
?
?
?
?
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的FrameLayout(帧布局)的基本使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AlertDialog(对话框)的基本使
- 下一篇: PercentFrameLayout(百