【代码】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

相关文章

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

Java中Map.Entry()含义及方法使用代码

《Java中Map.Entry()含义及方法使用代码》:本文主要介绍Java中Map.Entry()含义及方法使用的相关资料,Map.Entry是Java中Map的静态内部接口,用于表示键值对,其... 目录前言 Map.Entry作用核心方法常见使用场景1. 遍历 Map 的所有键值对2. 直接修改 Ma

深入解析 Java Future 类及代码示例

《深入解析JavaFuture类及代码示例》JavaFuture是java.util.concurrent包中用于表示异步计算结果的核心接口,下面给大家介绍JavaFuture类及实例代码,感兴... 目录一、Future 类概述二、核心工作机制代码示例执行流程2. 状态机模型3. 核心方法解析行为总结:三

python获取cmd环境变量值的实现代码

《python获取cmd环境变量值的实现代码》:本文主要介绍在Python中获取命令行(cmd)环境变量的值,可以使用标准库中的os模块,需要的朋友可以参考下... 前言全局说明在执行py过程中,总要使用到系统环境变量一、说明1.1 环境:Windows 11 家庭版 24H2 26100.4061

pandas实现数据concat拼接的示例代码

《pandas实现数据concat拼接的示例代码》pandas.concat用于合并DataFrame或Series,本文主要介绍了pandas实现数据concat拼接的示例代码,具有一定的参考价值,... 目录语法示例:使用pandas.concat合并数据默认的concat:参数axis=0,join=

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio

C#代码实现解析WTGPS和BD数据

《C#代码实现解析WTGPS和BD数据》在现代的导航与定位应用中,准确解析GPS和北斗(BD)等卫星定位数据至关重要,本文将使用C#语言实现解析WTGPS和BD数据,需要的可以了解下... 目录一、代码结构概览1. 核心解析方法2. 位置信息解析3. 经纬度转换方法4. 日期和时间戳解析5. 辅助方法二、L

Python使用Code2flow将代码转化为流程图的操作教程

《Python使用Code2flow将代码转化为流程图的操作教程》Code2flow是一款开源工具,能够将代码自动转换为流程图,该工具对于代码审查、调试和理解大型代码库非常有用,在这篇博客中,我们将深... 目录引言1nVflRA、为什么选择 Code2flow?2、安装 Code2flow3、基本功能演示

IIS 7.0 及更高版本中的 FTP 状态代码

《IIS7.0及更高版本中的FTP状态代码》本文介绍IIS7.0中的FTP状态代码,方便大家在使用iis中发现ftp的问题... 简介尝试使用 FTP 访问运行 Internet Information Services (IIS) 7.0 或更高版本的服务器上的内容时,IIS 将返回指示响应状态的数字代

MySQL 添加索引5种方式示例详解(实用sql代码)

《MySQL添加索引5种方式示例详解(实用sql代码)》在MySQL数据库中添加索引可以帮助提高查询性能,尤其是在数据量大的表中,下面给大家分享MySQL添加索引5种方式示例详解(实用sql代码),... 在mysql数据库中添加索引可以帮助提高查询性能,尤其是在数据量大的表中。索引可以在创建表时定义,也可