我得到了这个surficeview
<SurfaceViewandroid:id="@+id/videoview"android:layout_width="720px"android:layout_height="480px"/>
我如何管理自动设置尺寸以显示尺寸? 因为每个Android手机都有另一个显示尺寸?
谢谢!
答案 0 :(得分:1)
你必须在onSurfaceCreated()中捕获它并尝试在那里调整它...
private class surfaceCallback implements SurfaceHolder.Callback
{
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
if (holder == videoHolder)
{
Log.e(TAG, "video surfaceChanged: f: " + format + ", w: " + width + ", h: " + height);
//resize it here maybe?
} else
{
Log.e(TAG, "Unknown surface: f: " + format + ", w: " + width + ", h: " + height);
assert (false);
}
}
@Override
public void surfaceCreated(SurfaceHolder holder)
{
Log.e(TAG, "surfaceCreated");
}
@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
Log.e(TAG, "surfaceDestroyed");
}
}
获得显示尺寸的一种可能方法......
//measured android resolution
WindowManager win = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
Display d = win.getDefaultDisplay();
Point measuredResolution = new Point();
d.getSize(measuredResolution); //measuredResolution now holds actual size.
答案 1 :(得分:1)
你在xml中定义它?然后在父容器中使用android:layout_width="fill_parent"
和相同的内容:)
否则,如果以编程方式执行此操作,请参阅@Shark的回答