Android examples for User Interface:View Property
Set View Frame via reflection
//package com.java2s; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static boolean view_setFrame(Object o, Class viewClazz, int left, int top, int right, int bottom) { boolean changed = false; try {/*from w w w. j a va2s . c om*/ Method[] methods = viewClazz.getDeclaredMethods(); Method method = null; for (Method m : methods) { if ("setFrame".equals(m.getName())) { method = m; break; } } // method = viewClazz.getDeclaredMethod("setFrame", new Class[]{Integer.class, Integer.class, Integer.class, Integer.class}); if (null != method) { changed = (Boolean) method.invoke(o, new Object[] { new Integer(left), new Integer(top), new Integer(right), new Integer(bottom) }); } // } catch (NoSuchMethodException e) { // // TODO Auto-generated catch block // e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return changed; } }