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

相关文章

uniapp接入微信小程序原生代码配置方案(优化版)

uniapp项目需要把微信小程序原生语法的功能代码嵌套过来,无需把原生代码转换为uniapp,可以配置拷贝的方式集成过来 1、拷贝代码包到src目录 2、vue.config.js中配置原生代码包直接拷贝到编译目录中 3、pages.json中配置分包目录,原生入口组件的路径 4、manifest.json中配置分包,使用原生组件 5、需要把原生代码包里的页面修改成组件的方

公共筛选组件(二次封装antd)支持代码提示

如果项目是基于antd组件库为基础搭建,可使用此公共筛选组件 使用到的库 npm i antdnpm i lodash-esnpm i @types/lodash-es -D /components/CommonSearch index.tsx import React from 'react';import { Button, Card, Form } from 'antd'

17.用300行代码手写初体验Spring V1.0版本

1.1.课程目标 1、了解看源码最有效的方式,先猜测后验证,不要一开始就去调试代码。 2、浓缩就是精华,用 300行最简洁的代码 提炼Spring的基本设计思想。 3、掌握Spring框架的基本脉络。 1.2.内容定位 1、 具有1年以上的SpringMVC使用经验。 2、 希望深入了解Spring源码的人群,对 Spring有一个整体的宏观感受。 3、 全程手写实现SpringM

代码随想录算法训练营:12/60

非科班学习算法day12 | LeetCode150:逆波兰表达式 ,Leetcode239: 滑动窗口最大值  目录 介绍 一、基础概念补充: 1.c++字符串转为数字 1. std::stoi, std::stol, std::stoll, std::stoul, std::stoull(最常用) 2. std::stringstream 3. std::atoi, std

Eclipse+ADT与Android Studio开发的区别

下文的EA指Eclipse+ADT,AS就是指Android Studio。 就编写界面布局来说AS可以边开发边预览(所见即所得,以及多个屏幕预览),这个优势比较大。AS运行时占的内存比EA的要小。AS创建项目时要创建gradle项目框架,so,创建项目时AS比较慢。android studio基于gradle构建项目,你无法同时集中管理和维护多个项目的源码,而eclipse ADT可以同时打开

android 免费短信验证功能

没有太复杂的使用的话,功能实现比较简单粗暴。 在www.mob.com网站中可以申请使用免费短信验证功能。 步骤: 1.注册登录。 2.选择“短信验证码SDK” 3.下载对应的sdk包,我这是选studio的。 4.从头像那进入后台并创建短信验证应用,获取到key跟secret 5.根据技术文档操作(initSDK方法写在setContentView上面) 6.关键:在有用到的Mo

android一键分享功能部分实现

为什么叫做部分实现呢,其实是我只实现一部分的分享。如新浪微博,那还有没去实现的是微信分享。还有一部分奇怪的问题:我QQ分享跟QQ空间的分享功能,我都没配置key那些都是原本集成就有的key也可以实现分享,谁清楚的麻烦详解下。 实现分享功能我们可以去www.mob.com这个网站集成。免费的,而且还有短信验证功能。等这分享研究完后就研究下短信验证功能。 开始实现步骤(新浪分享,以下是本人自己实现

Android我的二维码扫描功能发展史(完整)

最近在研究下二维码扫描功能,跟据从网上查阅的资料到自己勉强已实现扫描功能来一一介绍我的二维码扫描功能实现的发展历程: 首页通过网络搜索发现做android二维码扫描功能看去都是基于google的ZXing项目开发。 2、搜索怎么使用ZXing实现自己的二维码扫描:从网上下载ZXing-2.2.zip以及core-2.2-source.jar文件,分别解压两个文件。然后把.jar解压出来的整个c

android 带与不带logo的二维码生成

该代码基于ZXing项目,这个网上能下载得到。 定义的控件以及属性: public static final int SCAN_CODE = 1;private ImageView iv;private EditText et;private Button qr_btn,add_logo;private Bitmap logo,bitmap,bmp; //logo图标private st

Android多线程下载见解

通过for循环开启N个线程,这是多线程,但每次循环都new一个线程肯定很耗内存的。那可以改用线程池来。 就以我个人对多线程下载的理解是开启一个线程后: 1.通过HttpUrlConnection对象获取要下载文件的总长度 2.通过RandomAccessFile流对象在本地创建一个跟远程文件长度一样大小的空文件。 3.通过文件总长度/线程个数=得到每个线程大概要下载的量(线程块大小)。