Android translateanimation class as a dynamic menu

Source: Internet
Author: User

Effect

The code is very simple, mainly for the translateanimation class

Public translateanimation (INT fromxtype, float fromxvalue, int toxtype, float toxvalue, int fromytype, float
Fromyvalue, int toytype, float toyvalue) since: API Level 1

Constructor to use when building a translateanimation from code

Parameters
Fromxtype Specifies how fromxvalue shocould be interpreted. One of animation. Absolute, animation. relative_to_self, or animation. relative_to_parent.
Fromxvalue Change in X coordinate to apply at the start of the animation. This value can either be an absolute number if fromxtype is absolute, or a percentage (where 1.0 is 100%) otherwise.
Toxtype Specifies how toxvalue shocould be interpreted. One of animation. Absolute, animation. relative_to_self, or animation. relative_to_parent.
Toxvalue Change in X coordinate to apply at the end of the animation. This value can either be an absolute number if toxtype is absolute, or a percentage (where 1.0 is 100%) otherwise.
Fromytype Specifies how fromyvalue shocould be interpreted. One of animation. Absolute, animation. relative_to_self, or animation. relative_to_parent.
Fromyvalue Change in Y coordinate to apply at the start of the animation. This value can either be an absolute number if fromytype is absolute, or a percentage (where 1.0 is 100%) otherwise.
Toytype Specifies how toyvalue shocould be interpreted. One of animation. Absolute, animation. relative_to_self, or animation. relative_to_parent.
Toyvalue Change in Y coordinate to apply at the end of the animation. This value can either be an absolute number if toytype is absolute, or a percentage (where 1.0 is 100%) otherwise

The Code is as follows:

Package COM. lenovo. wufl. translateanimationmenu; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. view. animation. animation; import android. view. animation. translateanimation; import android. widget. button; import android. widget. linearlayout; import android. widget. textview; public class extends activity extends {private textview mmenu; private button mbutton; private translateanimation extends; private translateanimation mhideanimation; private Boolean isshow;/** called when the activity is first created. * // @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); initview (); initanimation ();} private void initview () {mmenu = (textview) findviewbyid (R. id. menu); mbutton = (button) findviewbyid (R. id. button); mbutton. setonclicklistener (this); mmenu. setvisibility (view. gone); isshow = false;} private void initanimation () {// move from self-location-1 times to your original location mshowanimation = new translateanimation (animation. relative_to_self, 0.0f, animation. relative_to_self, 0.0f, animation. relative_to_self,-1.0f, animation. relative_to_self, 0.0f); mhideanimation = new translateanimation (animation. relative_to_self, 0.0f, animation. relative_to_self, 0.0f, animation. relative_to_self, 0.0f, animation. relative_to_self,-1.0f); mshowanimation. setduration (500); mhideanimation. setduration (500) ;}@ overridepublic void onclick (view v) {If (v. GETID () = R. id. button) {If (isshow) {isshow = false; mmenu. startanimation (mhideanimation); mmenu. setvisibility (view. gone);} else {isshow = true; mmenu. startanimation (mshowanimation); mmenu. setvisibility (view. visible );}}}}

Layout:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:id="@+id/menu"        android:layout_width="fill_parent"        android:layout_height="68dp"        android:background="@android:color/darker_gray"        android:gravity="center"        android:text="I am a menu"        android:textColor="@android:color/background_dark" />    <Button        android:id="@+id/button"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_alignParentBottom="true"        android:text="show/hide menu" /></RelativeLayout>
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.