set View Match Parent - Android User Interface

Android examples for User Interface:View Parent

Description

set View Match Parent

Demo Code


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

public class Main {
    public static void setMatchParent(View v) {
        ViewGroup.LayoutParams lp = v.getLayoutParams();
        if (lp == null) {
            lp = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
            v.setLayoutParams(lp);/*from   www .ja v a 2 s  . co m*/
        } else {
            lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
            lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
            v.requestLayout();
        }
    }
}

Related Tutorials