Android examples for User Interface:View Size
Adjust the view size (width, height) to which you want to be.
//package com.java2s; import android.view.View; import android.view.ViewGroup.LayoutParams; public class Main { private static final int INDICATOR_KEEP_VIEW_SIZE = -100; /**/* ww w. ja v a 2s . c om*/ * Adjust the view size (width, height) to which you want to be. * * @param view * target view * @param width * the width, either {@link LayoutParams#WRAP_CONTENT}, * {@link LayoutParams#FILL_PARENT} (replaced by * {@link LayoutParams#MATCH_PARENT} in API Level 8), or a fixed * size in pixels * @param height * the height, either {@link LayoutParams#WRAP_CONTENT}, * {@link LayoutParams#FILL_PARENT} (replaced by * {@link LayoutParams#MATCH_PARENT} in API Level 8), or a fixed * size in pixels */ public static void adjustViewSize(View view, int width, int height) { final View target = view; LayoutParams layoutParams = target.getLayoutParams(); if (width != INDICATOR_KEEP_VIEW_SIZE) layoutParams.width = width; if (height != INDICATOR_KEEP_VIEW_SIZE) layoutParams.height = height; target.setLayoutParams(layoutParams); } }