package com.sheep.gamegroup.util.viewHelper;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.sheep.gamegroup.model.entity.Lp;


/**
 * Created by realicing on 2018/11/13.
 * realicing@sina.com
 */
public class LayoutParamsUtil {

    //重新设置margin和宽高
    public static void resetLayoutParams(View view, Lp lp) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (lp.getHeight() != Lp.NONE)
            layoutParams.height = lp.getHeight();
        if (lp.getWidth() != Lp.NONE)
            layoutParams.width = lp.getWidth();
        if (layoutParams instanceof RelativeLayout.LayoutParams) {
            if (lp.getTopMargin() != Lp.NONE)
                ((RelativeLayout.LayoutParams) layoutParams).topMargin = lp.getTopMargin();
            if (lp.getLeftMargin() != Lp.NONE)
                ((RelativeLayout.LayoutParams) layoutParams).leftMargin = lp.getLeftMargin();
            if (lp.getBottomMargin() != Lp.NONE)
                ((RelativeLayout.LayoutParams) layoutParams).bottomMargin = lp.getBottomMargin();
            if (lp.getRightMargin() != Lp.NONE)
                ((RelativeLayout.LayoutParams) layoutParams).rightMargin = lp.getRightMargin();
        } else if (layoutParams instanceof LinearLayout.LayoutParams) {
            if (lp.getTopMargin() != Lp.NONE)
                ((LinearLayout.LayoutParams) layoutParams).topMargin = lp.getTopMargin();
            if (lp.getLeftMargin() != Lp.NONE)
                ((LinearLayout.LayoutParams) layoutParams).leftMargin = lp.getLeftMargin();
            if (lp.getBottomMargin() != Lp.NONE)
                ((LinearLayout.LayoutParams) layoutParams).bottomMargin = lp.getBottomMargin();
            if (lp.getRightMargin() != Lp.NONE)
                ((LinearLayout.LayoutParams) layoutParams).rightMargin = lp.getRightMargin();
        }
    }
}
