set View Wrap Content - Android User Interface

Android examples for User Interface:View Property

Description

set View Wrap Content

Demo Code


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

public class Main {
    public static void setWrapContent(View v) {
        ViewGroup.LayoutParams lp = v.getLayoutParams();
        if (lp == null) {
            lp = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            v.setLayoutParams(lp);//  ww w  . j a  v  a 2s  .c  o m
        } else {
            lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            v.requestLayout();
        }
    }
}

Related Tutorials