set View Hardware Layer - Android User Interface

Android examples for User Interface:View Layer

Description

set View Hardware Layer

Demo Code


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.util.Log;
import android.view.View;

public class Main {
  private static final String TAG = "";
  private static final int LAYER_TYPE_HARDWARE = 2;

  public static void setHardwareLayer(View view) {
    setLayerType(view, LAYER_TYPE_HARDWARE);
  }/*w ww  .  j ava2 s. co m*/

  public static void setLayerType(View view, int type) {
    try {
      Class[] paramTypes = new Class[1];
      paramTypes[0] = Integer.TYPE;
      Method setLayerTypeMethod = view.getClass().getMethod("setLayerType",
          paramTypes);
      setLayerTypeMethod.invoke(view, type);
      Log.d(TAG, "setLayerType successfully called");
    } catch (NoSuchMethodException e) {
      // method does not exist in this api level
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    }
  }
}

Related Tutorials