Java tutorial
//package com.java2s; import android.content.res.Configuration; import android.content.res.Resources; public class Main { /** * Get a dimension for the specified orientation. * This method may be heavy since it updates the {@code resources} twice. */ public static float getDimensionForOrientation(Resources resources, int id, int orientation) { Configuration configuration = resources.getConfiguration(); if (configuration.orientation == orientation) { return resources.getDimension(id); } Configuration originalConfiguration = new Configuration(resources.getConfiguration()); try { configuration.orientation = orientation; resources.updateConfiguration(configuration, null); return resources.getDimension(id); } finally { resources.updateConfiguration(originalConfiguration, null); } } }