Textview-shadow Shadow Implementation

Source: Internet
Author: User

Directly on the code

1) Achieve common effects

 <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:shadowcolor= "#ff0000"ANDROID:SHADOWDX= "3"Android:shadowdy= "3"Android:shadowradius= "1"Android:text= "ABCDEFG"Android:textcolor= "#0000ff"android:textsize= "100SP" />

The operation results are as follows

2) Influence of each property value under test

1.

android:shadowradius= "0"

Results


So, just let
Shadowradius = 0, there will be no shadow display

2.
Android:shadowradius= "20"

Results

Its main control is the width of the shadow, its value is also large, the larger the shadow, and the lighter the color

3. Test the role of the Dx,dy

        android:shadowdx= "android:shadowdy="        30 "

Results

That is, the offset of the shadow.

Summarized as follows

1. Android:shadowcolor: The color of the shadow

2. ANDROID:SHADOWDX: Offset in the horizontal direction

3. Android:shadowdy: Offset in the vertical direction

4. Android:shadowradius: Is the radius of the shadow size

The above variables are all PX units. Also, if you want to use @dimen reference, you will get an error.

If you want to use it in your code, you can use the following methods

 Packagecom.example.imagetest;ImportAndroid. R.integer;Importandroid.app.Activity;Importandroid.graphics.drawable.Drawable;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.ImageView;ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {TextView TV;    Button BT; intA; floatT1; floatT2; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); TV=(TextView) Findviewbyid (r.id.tv); BT=(Button) Findviewbyid (R.ID.BT); A= 0; T1=getresources (). Getdimension (R.dimen.activity_horizontal_margin); T2=getresources (). Getdimension (R.dimen.activity_vertical_margin); Bt.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View arg0) {if(A = = 1) {                    //R.color No effecttv.setshadowlayer (t1, T1, T1, R.COLOR.AAA); A= 0; } Else{tv.setshadowlayer (t2, T2, T2,0x800000ff); A= 1; } bt.settext (A+ "");    }        }); }        }

The Setshadowlayer method.

Setshadowlayer (radius, dx, dy, color);

Its four parameters, respectively, corresponding to the above four properties

Four attribute values, either write directly or use GetResource for a one-step conversion.

Textview-shadow Shadow Implementation

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.