Search code examples
androidandroid-mediaplayerandroid-viewandroid-videoviewandroid-video-player

Change size of VideoView at runtime


I have used this code to change videoview during rumtime
So, I am using this code

VideoView video;
DisplayMetrics dm;
dm=new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);
    height=dm.heightPixels;
    width=dm.widthPixels;

    video.setMinimumHeight(height);
    video.setMinimumWidth(width);

and on clicking of Menu item I am using this

public boolean onOptionsItemSelected(MenuItem item)
{
    switch(item.getItemId())
    {
        case SMALL:
                video.setMinimumHeight(height/2);
                video.setMinimumWidth(width/2);
                Toast.makeText(getApplicationContext(), "Small called", Toast.LENGTH_LONG).show();
            break;
        case DEFAULT:
            video.setMinimumHeight(height);
            video.setMinimumWidth(width);
            Toast.makeText(getApplicationContext(), "Default called", Toast.LENGTH_LONG).show();
            break;
    }   
    return super.onOptionsItemSelected(item);
}

But Still it is not getting changed.... Can anybody help??


Solution

  • You need to use video.layout(left, top, right, bottom); for your purpose.

    Can you try this once.

    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch(item.getItemId())
        {
            case SMALL:
                // YOU CAN CREATE LEFT, TOP, RIGHT, BOTTOM FOR YOUR VIEW AND SET.
                int left = video.getLeft();
                int top = video.getTop();
                int right = left + (width / 2);
                int botton = top + (height / 2);
                video.layout(left, top, right, bottom);
                Toast.makeText(getApplicationContext(), "Small called", Toast.LENGTH_LONG).show();
                break;
            case DEFAULT:
                    // YOU CAN CREATE LEFT, TOP, RIGHT, BOTTOM FOR YOUR VIEW AND SET.
                int left = video.getLeft();
                int top = video.getTop();
                int right = left + (width);
                int botton = top + (height);
                video.layout(left, top, right, bottom);
                    Toast.makeText(getApplicationContext(), "Default called", Toast.LENGTH_LONG).show();
                break;
        }   
        return super.onOptionsItemSelected(item);
    }
    

    I think it should work.