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

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

 


 

 

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

 

整个Activity是RelativeLayout。介是关键。

 

 

我做这样的Layout,起初目的是把底部那个蓝色的菜单条固定在屏幕底部,后来要用一个操作提示,刚好RelativeLayout适合。

 

RelativeLayout布局方式,有点类似CSS+DIV的Float,但RelativeLayout是可以重叠的。重叠的效果就类似上面图片效果,操作提示的图片 就叠在后面一堆控件的上方。

RelativeLayout的组件层次排序,好像是按其标签内组件从上到下递增排序,即是说,最后一个组件显示在最上方。

 

以下是上面界面的XML布局文件:(注意看里面那句注释)

 

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout  
  3.   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   android:orientation="vertical"  
  5.   android:layout_width="fill_parent"  
  6.   android:layout_height="fill_parent"  
  7.   android:background="@color/activityBGColor"  
  8.   >  
  9.   <ImageView   
  10.     android:src="@drawable/titleimg"  
  11.     android:layout_height="wrap_content"   
  12.     android:layout_width="fill_parent"  
  13.     android:layout_alignParentTop="true"  
  14.     android:id="@+id/activityTitle"  
  15.   />  
  16.   <ListView   
  17.   android:id="@+id/categoryList"   
  18.   android:layout_below="@id/activityTitle"  
  19.   android:layout_height="wrap_content"   
  20.   android:layout_width="fill_parent"  
  21.   android:cacheColorHint="@color/listHintColor"  
  22.   >  
  23.   </ListView>  
  24.   <LinearLayout   
  25.     android:orientation="horizontal"  
  26.     android:layout_width="fill_parent"  
  27.     android:layout_height="wrap_content"  
  28.     android:layout_alignParentBottom="true"  
  29.     android:background="@drawable/menubg"  
  30.     android:gravity="center_horizontal"  
  31.   >  
  32.     <ImageButton   
  33.         android:id="@+id/adbtn"  
  34.         android:layout_width="fill_parent"  
  35.         android:layout_height="wrap_content"  
  36.         android:src="@drawable/adbtn"  
  37.         android:background="@drawable/menubg"  
  38.     />  
  39.   </LinearLayout>  
  40.   
  41. <!-- 这个ImageView就是那个操作提示图片控件,它排在最后面,但显示在最顶。 --->  
  42.   <ImageView   
  43.     android:src="@drawable/tip"  
  44.     android:layout_height="fill_parent"   
  45.     android:layout_width="fill_parent"  
  46.     android:id="@+id/helpTip"  
  47.     android:layout_alignParentBottom="true"  
  48.     android:keepScreenOn="true"  
  49.     android:onClick="hideTip"  
  50.   />  
  51. </RelativeLayout>  
 

 

然后,对那个图片进行相应操作控制就行了。效果就这样。

 

图片透明呢,可以用PNG透明来实现,我就是这么做的。

注:转自http://chenyoca.iteye.com/blog/1188807

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值