Android examples for User Interface:View Size
Adjust the view width 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 . j a va 2 s .c om * Adjust the view width 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 */ public static void adjustViewWidth(View view, int width) { adjustViewSize(view, width, INDICATOR_KEEP_VIEW_SIZE); } /** * 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); } }