日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android学习指南 第六讲:用户界面 View(二)

發布時間:2024/4/15 Android 60 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android学习指南 第六讲:用户界面 View(二) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本講內容:常用Layout介紹: AbsoluteLayout和RelativeLayout 點此下載:<ignore_js_op>?lesson6.zip?(114.78 KB, 下載次數: 362) 3、絕對布局 AbsoluteLayout 絕對定位AbsoluteLayout,又可以叫做坐標布局,可以直接指定子元素的絕對位置,這種布局簡單直接,直觀性強,但是由于手機屏幕尺寸差別比較大,使用絕對定位的適應性會比較差。 下面我們舉一個例子看看:例子里的機器人圖片大小是250X250,可以看到我們使用android:layout_x和android:layout_y來指定子元素的縱橫坐標。 <?xml version=”1.0″ encoding=”utf-8″?> <AbsoluteLayout android:id=”@+id/AbsoluteLayout01″ android:layout_width=”fill_parent” android:layout_height=”fill_parent” xmlns:android=”http://schemas.android.com/apk/res/android” android:background=”#fff”><ImageView android:src=”@drawable/android” android:layout_y=”40dip” android:layout_width=”wrap_content” android:layout_x=”35dip” android:id=”@+id/ImageView01″ android:layout_height=”wrap_content”> </ImageView> <TextView android:layout_height=”wrap_content” android:layout_width=”fill_parent” android:id=”@+id/TextView01″ android:text=”Android2.2 學習指南” android:textColor=”#0f0″ android:textSize=”28dip” android:layout_y=”330dip” android:layout_x=”35dip“> </TextView> <TextView android:layout_height=”wrap_content” android:layout_width=”fill_parent” android:id=”@+id/TextView02″ android:text=”圖文并茂,理論清晰,操作性強” android:textColor=”#333″ android:textSize=”18dip” android:layout_y=”365dip” android:layout_x=”35dip“> </TextView> </AbsoluteLayout>

讓我們看一下在WQVGA的模擬器下的顯示效果:

<ignore_js_op> 再在WVGA800的模擬器下看看顯示效果: <ignore_js_op> Tip: 在絕對定位中,如果子元素不設置layout_x和layout_y,那么它們的默認值是0,也就是說它會像在FrameLayout一樣這個元素會出現在左上角。 4、相對布局 RelativeLayout 相對布局 RelativeLayout 允許子元素指定它們相對于其父元素或兄弟元素的位置,這是實際布局中最常用的布局方式之一。它靈活性大很多,當然屬性也多,操作難度也大,屬性之間產生沖突的的可能性也大,使用相對布局時要多做些測試。 下面我們用相對布局再做一次上面的例子,首先放置一個圖片,其它兩個文本分別相對上一個元素定位: <?xml version=”1.0″ encoding=”utf-8″?><RelativeLayout android:id=”@+id/RelativeLayout01″ android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:background=”#fff” xmlns:android=”http://schemas.android.com/apk/res/android”><ImageView android:id=”@+id/ImageView01″ android:src=”@drawable/android” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:layout_marginTop=”40dip” > </ImageView> <TextView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:id=”@+id/TextView01″ android:text=”Android2.2 學習指南” android:textColor=”#0f0″ android:textSize=”28dip” android:layout_below=”@id/ImageView01″ android:layout_centerHorizontal=”true” android:layout_marginTop=”10dip”> </TextView> <TextView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:id=”@+id/TextView02″ android:text=”圖文并茂,理論清晰,操作性強” android:textColor=”#333″ android:textSize=”18dip” android:layout_below=”@id/TextView01″ android:layout_centerHorizontal=”true” android:layout_marginTop=”5dip“> </TextView> </RelativeLayout>

讓我們看一下在WQVGA的模擬器下的顯示效果:

<ignore_js_op> 再看一下在更大屏幕(WVGA800)模擬器上的顯示效果: <ignore_js_op> 從上圖可以看到界面效果基本保持了一致,而不是像絕對定位一樣龜縮在左上角;同學們看到自動縮放的功能是采用了dip做單位帶來的好處。關于dip,不懂的同學可以看我在開發小知識里寫的專門的文章。 下面介紹一下RelativeLayout用到的一些重要的屬性: 第一類:屬性值為true或false
android:layout_centerHrizontal? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 水平居中
android:layout_centerVertical? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???垂直居中
android:layout_centerInparent? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 相對于父元素完全居中
android:layout_alignParentBottom? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 貼緊父元素的下邊緣
android:layout_alignParentLeft? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?貼緊父元素的左邊緣
android:layout_alignParentRight? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 貼緊父元素的右邊緣
android:layout_alignParentTop? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?貼緊父元素的上邊緣
android:layout_alignWithParentIfMissing? ?? ?? ?? ?? ?? ?? ?? ?? ? 如果對應的兄弟元素找不到的話就以父元素做參照物 第二類:屬性值必須為id的引用名“@id/id-name”
android:layout_below? ?? ?? ?? ?? ?? ?? ?? ???在某元素的下方
android:layout_above? ?? ?? ?? ?? ?? ?? ?? ???在某元素的的上方
android:layout_toLeftOf? ?? ?? ?? ?? ?? ?? ???在某元素的左邊
android:layout_toRightOf? ?? ?? ?? ?? ?? ?? ?在某元素的右邊 android:layout_alignTop? ?? ?? ?? ?? ?? ?? ? 本元素的上邊緣和某元素的的上邊緣對齊
android:layout_alignLeft? ?? ?? ?? ?? ?? ?? ? 本元素的左邊緣和某元素的的左邊緣對齊
android:layout_alignBottom? ?? ?? ?? ?? ???本元素的下邊緣和某元素的的下邊緣對齊
android:layout_alignRight? ?? ?? ?? ?? ?? ???本元素的右邊緣和某元素的的右邊緣對齊 第三類:屬性值為具體的像素值,如30dip,40px
android:layout_marginBottom? ?? ?? ?? ???離某元素底邊緣的距離
android:layout_marginLeft? ?? ?? ?? ?? ?? ? 離某元素左邊緣的距離
android:layout_marginRight? ?? ?? ?? ?? ???離某元素右邊緣的距離
android:layout_marginTop? ?? ?? ?? ?? ?? ? 離某元素上邊緣的距離 我們再把上面的例子重新做一遍,這一次多放一些屬性在里面,大家試驗一下: <?xml version=”1.0″ encoding=”utf-8″?><RelativeLayout android:id=”@+id/RelativeLayout01″ android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:background=”#cfff” 色彩的設置是argb,第一個c是透明度 xmlns:android=”http://schemas.android.com/apk/res/android”><ImageView android:id=”@+id/ImageView01″ android:src=”@drawable/android” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”40dip” android:layout_centerHorizontal=”true”> </ImageView><TextView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:id=”@+id/TextView01″ android:text=”Android2.2 學習指南” android:textColor=”#0f0″ android:textSize=”28dip” android:layout_below=”@id/ImageView01″ android:layout_centerHorizontal=”true” android:layout_marginTop=”10dip”> </TextView><TextView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:id=”@+id/TextView02″ android:text=”圖文并茂,理論清晰,操作性強” android:textColor=”#333″ android:textSize=”18dip” android:layout_below=”@id/TextView01″ android:layout_centerHorizontal=”true” android:layout_marginTop=”5dip”> </TextView><TextView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:id=”@+id/TextView03″ android:text=”alignTop” android:textColor=”#333″ android:textSize=”18dip” android:layout_alignTop=”@id/ImageView01″ 和ImageView01上邊緣對齊 android:layout_centerHorizontal=”true”> </TextView><TextView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:id=”@+id/TextView04″ android:text=”alignLeft” android:textColor=”#333″ android:textSize=”18dip” android:layout_alignLeft=”@id/ImageView01″ android:layout_centerHorizontal=”true”> </TextView><TextView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:id=”@+id/TextView05″ android:text=”alignRight” android:textColor=”#333″ android:textSize=”18dip” android:layout_alignRight=”@id/ImageView01″ android:layout_centerHorizontal=”true”> </TextView><TextView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:id=”@+id/TextView06″ android:text=”alignBottom” android:textColor=”#333″ android:textSize=”18dip” android:layout_alignBottom=”@id/ImageView01″ android:layout_centerHorizontal=”true”> </TextView> </RelativeLayout>

<ignore_js_op>

好吧今天就講到這里。

轉載于:https://www.cnblogs.com/yinxiangpei/articles/2495701.html

總結

以上是生活随笔為你收集整理的Android学习指南 第六讲:用户界面 View(二)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。