Change width of view. - Android User Interface

Android examples for User Interface:View Size

Description

Change width of view.

Demo Code


//package com.java2s;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

public class Main {
    /**//  w  w w . ja va 2 s.co m
     * Change width of view.
     * @param view View to change width.
     * @param width New width.
     */
    public static void setWidth(View view, int width) {
        if (view == null)
            return;
        LayoutParams params = view.getLayoutParams();
        params.width = width;
        view.requestLayout();
    }
}

Related Tutorials