set View Width - Android User Interface

Android examples for User Interface:View Size

Description

set View Width

Demo Code


//package com.java2s;

import android.view.View;
import android.view.ViewGroup;

public class Main {
    public static void setWidth(View view, int width) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        if (null == lp) {
            lp = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }/*from w  w  w  . j  a v a 2s . c o m*/
        lp.width = width;
        view.setLayoutParams(lp);
    }
}

Related Tutorials