(Android Control) ImageView control development effect Summary (border effect, filter effect)

Source: Internet
Author: User
Tags image filter
Document directory
  • Preface
  • 1 ImageView add rounded border
  • 2. Set the Image view to have a filter effect. The following example shows the gray effect.
Preface

This article summarizes the effects used in ImageView development.

1 ImageView add rounded border

The following is an example

Implementation Process description:

Step One: Set the Padding of ImageView to a certain width, and set android: adjustViewBounds to True.

 

 <ImageView                                android:background="@drawable/img_on"                                android:id="@+id/imageViewt"                                android:adjustViewBounds="true"                                android:padding="2dp"                                android:layout_width="fill_parent"                                android:layout_height="wrap_content"                                android:src="@drawable/icon" />

Step Two: Set the image background

<?xml version="1.0" encoding="utf-8"?><shape    xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle"    android:useLevel="false">     <corners     android:radius="5dp"    /> <gradient     android:startColor="#848484"     android:centerColor="#848484"     android:useLevel="false"     android:type="linear"     android:angle="90"     android:endColor="#848484">        </gradient>   </shape>

 

2. Set the Image view to have a filter effect. The following example shows the gray effect.

Implementation Process description:

Use the ColorFilter attribute of the image object to set the grayscale channel of ColorMatrixColorFilter and pass it to the ColorFilter attribute.

Note two points: 1. The effect of the image filter is only added to the layer, not the actual modification of the image.

2 If you apply a filter effect to a single image, the image will also be used in other places with a filter effect.

The following is the actual implementation code

public final float[] BT_SELECTED = new float[] {1,0,0,0,99,0,1,0,0,99,0,0,1,0,99,0,0,0,1,0};     public final float[] BT_NOT_SELECTED = new float[]  {1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0};;     public final static float[] BT_SELECTED1 = new float[] {                     0.338f, 0.339f, 0.332f, 0, 0,                   0.338f, 0.339f, 0.332f, 0, 0,              0.338f, 0.339f, 0.332f, 0, 0,              0, 0, 0, 1, 0          };  @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                ImageView  ib2;        ib1 = (ImageView) findViewById(R.id.imageViewt);        ib2 = (ImageView) findViewById(R.id.imageView2);          ib1.setOnTouchListener(new  ImageView.OnTouchListener()        {            @Override            public boolean onTouch(View v, MotionEvent event) {                if (event.getAction() == MotionEvent.ACTION_DOWN) {                                    ib1.setImageResource(R.drawable.icon1);                    ib1.getDrawable().setColorFilter(                                new ColorMatrixColorFilter(BT_SELECTED));                                ib1.setImageDrawable(ib1.getDrawable());                } else if (event.getAction() == MotionEvent.ACTION_UP) {                    ib1.getDrawable().clearColorFilter();                                    ib1.getDrawable().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED));                    ib1.setImageResource(R.drawable.icon2);                }                return false;            }        });                   }

 

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.