Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在运行时更改VideoView的大小_Android_Android Mediaplayer_Android View_Android Videoview_Android Video Player - Fatal编程技术网

Android 在运行时更改VideoView的大小

Android 在运行时更改VideoView的大小,android,android-mediaplayer,android-view,android-videoview,android-video-player,Android,Android Mediaplayer,Android View,Android Videoview,Android Video Player,我已使用此代码在rumtime期间更改视频视图 所以,我使用这个代码 VideoView video; DisplayMetrics dm; dm=new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); height=dm.heightPixels; width=dm.widthPixels; video.setMinimumHeight(height);

我已使用此代码在rumtime期间更改视频视图
所以,我使用这个代码

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

但它仍然没有改变。。。。有人能帮忙吗???

你需要使用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);
}

我想应该行。

thnx 4您的答案。。。。但它对视频没有任何影响。。。视频正在按原样播放…:(实际上我已经做过了,你需要使用video.layout(左、上、右、下)在运行时更改其大小。刚才我编辑了我的答案。如果您无法计算左、上、右、下,请通知我,我将计算并更新我的答案。它可以工作..Thnx…但您可以告诉我如何计算左、上、右、下??所以您应该将投票标记作为答案,以便对其他人有帮助。看起来您是s的新手(:)