【代码】android 遮罩层效果

2024-06-19 04:18
文章标签 代码 android 效果 遮罩

本文主要是介绍【代码】android 遮罩层效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

看到一本电子杂志上有遮罩层的效果,感觉很漂亮,以为很麻烦,搜索了很多关于android遮罩层的,也没有得出一点思路,原来就是一个透明的效果,然后上面弹出的控件是透明或者半透明之类的,可以选择颜色,还是#ARBG,其中A就是传说中的透明色的值(可以根据需要设置透明的效果),废话不多说了,发一个简单的Demo吧,是我山寨的那本杂志的效果:(由于杂志内容主要是图片,弹出层才是给出的文字信息,所以我猜测是用Gallery显示的杂志内容)


xml布局文件:

<?xml version="1.0" encoding="utf-8"?>   
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:id="@+id/layout"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   >   <Gallery   android:id="@+id/showGallery"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:spacing="0dip"   />   <RelativeLayout   android:orientation="horizontal"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:layout_gravity="bottom"   android:background="#86222222"   >   <TextView   android:id="@+id/titleTextView"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_toRightOf="@id/secondKillButton"  android:text="00000000" android:textColor="#ff0000"   />   <Button   android:id="@+id/unfoldButton"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_alignParentRight="true"   android:text="展开"   />   </RelativeLayout>   
</FrameLayout>


主要的代码也很简单,还有一个简单的Adapter,有不理解的朋友可以看我之前的blog


[java] 
view plaincopy 
package oneRain.UpMagazine;  
import java.io.File;  
import java.util.ArrayList;  
import java.util.List;  
import android.app.Activity;  
import android.graphics.Bitmap;  
import android.graphics.BitmapFactory;  
import android.graphics.Color;  
import android.os.Bundle;  
import android.view.Gravity;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.view.ViewGroup;  
import android.view.Window;  
import android.widget.AdapterView;  
import android.widget.AdapterView.OnItemSelectedListener;  
import android.widget.BaseAdapter;  
import android.widget.Button;  
import android.widget.FrameLayout;  
import android.widget.Gallery;  
import android.widget.ImageView;  
import android.widget.TextView;  
public class ShowActivity extends Activity  
{  private int i = 1;  private int pos = 0;  private List<String> contents = null;  private static final String DIR = "/mnt/sdcard/UpMagazine/2010/content/";  //设置是否展开  private boolean isFolded = true;  //设置控件  private FrameLayout layout = null;  private Gallery showGallery = null;  private Button unfoldButton = null;  private TextView textView = null;  private TextView titleTextView = null;  public void onCreate(Bundle savedInstanceState)  {  super.onCreate(savedInstanceState);  requestWindowFeature(Window.FEATURE_NO_TITLE);  setContentView(R.layout.show);  initView();  }  @Override  protected void onResume()   {  // TODO Auto-generated method stu  super.onResume();  isFolded = true;  }  //初始化  private void initView()  {     contents = new ArrayList<String>();  File dir = new File(DIR);  File[] files = dir.listFiles();  for(int i=0; i<files.length; i++)  {  contents.add(DIR + files[i].getName());  }  layout = (FrameLayout)findViewById(R.id.layout);  unfoldButton = (Button)findViewById(R.id.unfoldButton);  unfoldButton.setOnClickListener(new UnfoldClickListener());  showGallery = (Gallery)findViewById(R.id.showGallery);  showGallery.setOnItemSelectedListener(new GalleryOnItemSelectedListener());  showGallery.setAdapter(new ShowAdapter());  titleTextView = (TextView)findViewById(R.id.titleTextView);  }  //滑动监听  private class GalleryOnItemSelectedListener implements OnItemSelectedListener  {  public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,  long arg3)   {  // TODO Auto-generated method stub  pos = arg2 + 1;  titleTextView.setText("第" + pos +"个主题");  }  public void onNothingSelected(AdapterView<?> arg0)  {  // TODO Auto-generated method stub  }  }  //按钮监听,展开一个透明的显示文本的遮挡层  private class UnfoldClickListener implements OnClickListener  {  public void onClick(View v)   {         if(isFolded)  {  textView = new TextView(ShowActivity.this);  textView.setTextColor(Color.BLUE);  textView.setTextSize(20);  textView.setText("滚滚长江东逝水,浪花淘尽英雄。/n" +  "是非成败转头空,/n" +  "青山依旧在,几度夕阳红。/n" +  "白发渔樵江渚上,惯看秋月春风。 /n" +  "一壶浊酒喜相逢,/n" +  "古今多少事,都付笑谈中。");  textView.setGravity(Gravity.CENTER);  textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,   ViewGroup.LayoutParams.FILL_PARENT));  textView.setBackgroundColor(Color.parseColor("#86222222"));  unfoldButton.setText("收回");  isFolded = false;  layout.addView(textView);  }  else  {  unfoldButton.setText("展开");  isFolded = true;  layout.removeView(textView);  }  }  }  private class ShowAdapter extends BaseAdapter  {  public int getCount()   {  // TODO Auto-generated method stub  return contents.size();  }  public Object getItem(int position)   {  // TODO Auto-generated method stub  return position;  }  public long getItemId(int position)   {  // TODO Auto-generated method stub  return 0;  }  public View getView(int position, View convertView, ViewGroup parent)   {  // TODO Auto-generated method stub  ImageView i = new ImageView(ShowActivity.this);  Bitmap bm = BitmapFactory.decodeFile(contents.get(position));  
//          i.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT,  
//                  Gallery.LayoutParams.FILL_PARENT));  i.setScaleType(ImageView.ScaleType.FIT_XY);  i.setImageBitmap(bm);  return i;  }  }  
}  


效果如下:

http://pic002.cnblogs.com/images/2012/274740/2012031710144442.gif


http://pic002.cnblogs.com/images/2012/274740/2012031710151518.gif


本文出自 “清源教育” 博客,转载请注明此处,谢谢!欢迎登录清源教育官网,查看更多视频教程。

这篇关于【代码】android 遮罩层效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1073978

相关文章

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

MySQL数据库的内嵌函数和联合查询实例代码

《MySQL数据库的内嵌函数和联合查询实例代码》联合查询是一种将多个查询结果组合在一起的方法,通常使用UNION、UNIONALL、INTERSECT和EXCEPT关键字,下面:本文主要介绍MyS... 目录一.数据库的内嵌函数1.1聚合函数COUNT([DISTINCT] expr)SUM([DISTIN

Java实现自定义table宽高的示例代码

《Java实现自定义table宽高的示例代码》在桌面应用、管理系统乃至报表工具中,表格(JTable)作为最常用的数据展示组件,不仅承载对数据的增删改查,还需要配合布局与视觉需求,而JavaSwing... 目录一、项目背景详细介绍二、项目需求详细介绍三、相关技术详细介绍四、实现思路详细介绍五、完整实现代码

Go语言代码格式化的技巧分享

《Go语言代码格式化的技巧分享》在Go语言的开发过程中,代码格式化是一个看似细微却至关重要的环节,良好的代码格式化不仅能提升代码的可读性,还能促进团队协作,减少因代码风格差异引发的问题,Go在代码格式... 目录一、Go 语言代码格式化的重要性二、Go 语言代码格式化工具:gofmt 与 go fmt(一)

Android DataBinding 与 MVVM使用详解

《AndroidDataBinding与MVVM使用详解》本文介绍AndroidDataBinding库,其通过绑定UI组件与数据源实现自动更新,支持双向绑定和逻辑运算,减少模板代码,结合MV... 目录一、DataBinding 核心概念二、配置与基础使用1. 启用 DataBinding 2. 基础布局

Android ViewBinding使用流程

《AndroidViewBinding使用流程》AndroidViewBinding是Jetpack组件,替代findViewById,提供类型安全、空安全和编译时检查,代码简洁且性能优化,相比Da... 目录一、核心概念二、ViewBinding优点三、使用流程1. 启用 ViewBinding (模块级

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

Python如何去除图片干扰代码示例

《Python如何去除图片干扰代码示例》图片降噪是一个广泛应用于图像处理的技术,可以提高图像质量和相关应用的效果,:本文主要介绍Python如何去除图片干扰的相关资料,文中通过代码介绍的非常详细,... 目录一、噪声去除1. 高斯噪声(像素值正态分布扰动)2. 椒盐噪声(随机黑白像素点)3. 复杂噪声(如伪