【代码】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调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

使用 sql-research-assistant进行 SQL 数据库研究的实战指南(代码实现演示)

《使用sql-research-assistant进行SQL数据库研究的实战指南(代码实现演示)》本文介绍了sql-research-assistant工具,该工具基于LangChain框架,集... 目录技术背景介绍核心原理解析代码实现演示安装和配置项目集成LangSmith 配置(可选)启动服务应用场景

前端原生js实现拖拽排课效果实例

《前端原生js实现拖拽排课效果实例》:本文主要介绍如何实现一个简单的课程表拖拽功能,通过HTML、CSS和JavaScript的配合,我们实现了课程项的拖拽、放置和显示功能,文中通过实例代码介绍的... 目录1. 效果展示2. 效果分析2.1 关键点2.2 实现方法3. 代码实现3.1 html部分3.2

Python中顺序结构和循环结构示例代码

《Python中顺序结构和循环结构示例代码》:本文主要介绍Python中的条件语句和循环语句,条件语句用于根据条件执行不同的代码块,循环语句用于重复执行一段代码,文章还详细说明了range函数的使... 目录一、条件语句(1)条件语句的定义(2)条件语句的语法(a)单分支 if(b)双分支 if-else(

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

MySQL数据库函数之JSON_EXTRACT示例代码

《MySQL数据库函数之JSON_EXTRACT示例代码》:本文主要介绍MySQL数据库函数之JSON_EXTRACT的相关资料,JSON_EXTRACT()函数用于从JSON文档中提取值,支持对... 目录前言基本语法路径表达式示例示例 1: 提取简单值示例 2: 提取嵌套值示例 3: 提取数组中的值注意

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

JAVA调用Deepseek的api完成基本对话简单代码示例

《JAVA调用Deepseek的api完成基本对话简单代码示例》:本文主要介绍JAVA调用Deepseek的api完成基本对话的相关资料,文中详细讲解了如何获取DeepSeekAPI密钥、添加H... 获取API密钥首先,从DeepSeek平台获取API密钥,用于身份验证。添加HTTP客户端依赖使用Jav

Java实现状态模式的示例代码

《Java实现状态模式的示例代码》状态模式是一种行为型设计模式,允许对象根据其内部状态改变行为,本文主要介绍了Java实现状态模式的示例代码,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来... 目录一、简介1、定义2、状态模式的结构二、Java实现案例1、电灯开关状态案例2、番茄工作法状态案例