今天通宵趕出來的效果,先看效果圖:
說說實現原理,當給代碼沒意思。
整個Activity是RelativeLayout。介是關鍵。
我做這樣的Layout,起初目的是把底部那個藍色的菜單條固定在屏幕底部,後來要用一個操作提示,剛好RelativeLayout適合。
RelativeLayout佈局方式,有點類似CSS+DIV的Float,但RelativeLayout是可以重疊的。重疊的效果就類似上面圖片效果,操作提示的圖片 就疊在後面一堆控件的上方。
RelativeLayout的組件層次排序,好像是按其標籤內組件從上到下遞增排序,即是說,最後一個組件顯示在最上方。
以下是上面界面的XML佈局文件:(注意看裏面那句註釋)
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/activityBGColor" > <ImageView android:src="@drawable/titleimg" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_alignParentTop="true" android:id="@+id/activityTitle" /> <ListView android:id="@+id/categoryList" android:layout_below="@id/activityTitle" android:layout_height="wrap_content" android:layout_width="fill_parent" android:cacheColorHint="@color/listHintColor" > </ListView> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@drawable/menubg" android:gravity="center_horizontal" > <ImageButton android:id="@+id/adbtn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/adbtn" android:background="@drawable/menubg" /> </LinearLayout> <!-- 這個ImageView就是那個操作提示圖片控件,它排在最後面,但顯示在最頂。 ---> <ImageView android:src="@drawable/tip" android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/helpTip" android:layout_alignParentBottom="true" android:keepScreenOn="true" android:onClick="hideTip" /> </RelativeLayout>
然後,對那個圖片進行相應操作控制就行了。效果就這樣。
圖片透明呢,可以用PNG透明來實現,我就是這麼做的。