[Code] android Mask Layer Effect

Source: Internet
Author: User
Tags transparent color

Seeing the effect of a mask layer in an electronic magazine, I felt very beautiful and thought it was very troublesome. I did not come up with any idea when I searched a lot about the android mask layer, it turns out to be a transparent effect, and the pop-up controls above are transparent or translucent. You can choose a color, or # ARBG, among them, A is the legendary transparent color value (you can set the transparent effect as needed). If you don't talk much about it, just send A simple Demo, the effect of the magazine I copied is: (because the content of the magazine is mainly pictures, the pop-up layer provides the text information, so I guess it is the content of the magazine displayed by Gallery)


Xml layout file:

<? 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 = "Expand"/> </RelativeLayout> </FrameLayout>


The main code is also very simple. There is also a simple Adapter. If you have any questions, you can read my previous 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; I Mport 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/"; // set whether to expand private boolean isFolded = true; // set the control 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. on Create (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); setContentView (R. layout. show); initView () ;}@ Override protected void onResume () {// TODO Auto-generated method stu super. onResume (); isFolded = true;} // initialize 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) fi NdViewById (R. id. titleTextView);} // slide listener 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 ("Number" + pos + "topic");} public void onNothingSelected (AdapterView <?> Arg0) {// TODO Auto-generated method stub} // click the listener to display a transparent text occlusion layer 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 ("rolling in the east of the Yangtze River, the waves are all heroes. /N "+" is not a success or failure turn empty,/n "+" Qingshan is still there, a few times sunset red. /N "+" white-haired fish on the river, used to see the spring breeze in autumn and moon. /N "+" a pot of turbid wine meets each other./n "+" all the past and times have been discussed with a smile. "); TextView. setGravity (Gravity. CENTER); textView. setLayoutParams (new ViewGroup. layoutParams (ViewGroup. layoutParams. FILL_PARENT, ViewGroup. layoutParams. FILL_PARENT); textView. setBackgroundColor (Color. parseColor ("#86222222"); unfoldButton. setText ("reclaim"); isFolded = false; layout. addView (textView);} else {unfoldButton. setText ("Expand"); 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 ;}}}


The effect is as follows:





This article is from the "Qingyuan Education" blog. For more information, see here. Thank you! Log on to Qingyuan education official website to view more video tutorials.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.