Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create alpha effect animation button android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 237
    Comment on it

    In my previous blog I have explain how to create animation button in android. Now in this below example I have created new animation button which is alpha effictive.

    Here I have added Button and TextView in activity_main xml layout then I have created new directory (anim) , In anim directory I have created new anim_alpha.xml layout. In MainActivity I have used AnimationUtils.loadAnimation function and setOnClickListener method. You can see below program it will clearly describe you how to create alpha effective Animation button in android.

    Step(1)activity_main.xml layout-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Animation Click"
            android:textAlignment="center"
            android:layout_marginTop="20dp"
            android:textSize="20dp"
            android:textColor="@color/colorPrimaryDark"/>
    
    
        <Button
            android:id="@+id/click"
            android:layout_gravity="center"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="Clich here" />
    
    
    </LinearLayout>

     

    Step(2)MainActivity-

    public class MainActivity extends AppCompatActivity {
    
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
    
    
                final Animation animAlpha = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
    
                Button btnAlpha = (Button)findViewById(R.id.click);
    
                btnAlpha.setOnClickListener(new Button.OnClickListener(){
    
                    @Override
                    public void onClick(View arg0) {
                        arg0.startAnimation(animAlpha);
                    }});
    
            }
        }

     

    Step(3)-Create new directory anim and created here new anim_alpha.xml layout-

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/linear_interpolator">
        <alpha
            android:fromAlpha="1.0"
            android:toAlpha="0.1"
            android:duration="500"
            android:repeatCount="1"
            android:repeatMode="reverse" />
    </set>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: