在运行时更改VideoView的大小

时间:2013-11-26 06:47:51

标签: android android-mediaplayer android-view android-videoview android-video-player

我在朗姆酒时使用此代码更改了视频 所以,我正在使用此代码

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

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

点击菜单项我正在使用

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);
}

但仍然没有改变......任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:6)

你需要使用video.layout(左,上,右,下);为了你的目的。

你可以尝试一次。

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);
}

我认为它应该有用。