用按钮调整图层的高度

adjust the height of the layer with a button

A simple code to adjust the height of the layer with a button.

Is there another way to do this?

Button btn=(Button)findViewById(R.id.btn);
final RelativeLayout ly=(RelativeLayout)findViewById(R.id.Relative);

btn.setOnClickListener(new OnClickListener()
{
    public void onClick(View v)
    {
        int height=ly.getHeight();

        if(height==0)
        {
            ly.getLayoutParams().height=200;
            ly.getLayoutParams().width=LayoutParams.MATCH_PARENT;    
            ly.requestLayout();

        }else if(height==200)
        {
            ly.getLayoutParams().height=0;
            ly.getLayoutParams().width=LayoutParams.MATCH_PARENT;    
            ly.requestLayout();
        }
    }
});