set View X coordinate - Android User Interface

Android examples for User Interface:View Position

Description

set View X coordinate

Demo Code


//package com.java2s;
import android.os.Build;
import android.view.View;
import android.view.animation.TranslateAnimation;

public class Main {
    public static void setX(View view, float x) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            TranslateAnimation anim = new TranslateAnimation(x, x, 0, 0);
            anim.setFillAfter(true);/*  w  w  w .jav a2s .c om*/
            anim.setDuration(0);
            view.startAnimation(anim);
        } else {
            view.setX(x);
        }
    }
}

Related Tutorials