Android作半透明操作提示图片的方法

Android做半透明操作提示图片的方法

 

今天通宵赶出来的效果,先看效果图:

 


Android作半透明操作提示图片的方法

 

 

说说实现原理,当给代码没意思。

 

整个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透明来实现,我就是这么做的。