由于我MainActivity类的布局部分我有一个SurfaceView:与SurfaceHolder.setFixedSize(宽度,高度)设置一个SurfaceView的大小
<LinearLayout
android:id="@+id/screen_game"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000FF"
android:orientation="vertical"
>
<Button
android:id="@+id/button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<com.ecslayout.BackgammonBoardView
android:id="@+id/backgammonBoardView1"
android:layout_width="100dp"
android:layout_height="100dp" />
</LinearLayout>
我为我的SurfaceView骨架类中定义的(I省略很多简单的代码)。 Inside surfaceCreated我正在尝试使用许多不同的方式来设置画布的大小 。从100dp x 100dp开始,画布看起来并没有改变大小。我想尽办法叫setFixedSize似乎在所有的大小没有影响:
public class BackgammonBoardView extends SurfaceView implements SurfaceHolder.Callback {
public BackgammonBoardView(Context context, AttributeSet attrs) {
super(context, attrs);
Log.d(TAG,"SurfaceView Constructor.");
//register out interest in hearing about changes to our surface
SurfaceHolder holder = getHolder();
holder.addCallback(this);
}
//The method is firing just fine. I have the surfaceCreated output from Log.d
@Override
public void surfaceCreated(SurfaceHolder arg0) {
//Has no effect on size
//this.getHolder().setFixedSize(500, 500);
//Has no effect on size
//arg0.setFixedSize(500, 500);
//Has no effect on size
//SurfaceHolder holder = getHolder();
//holder.setFixedSize(500, 500);
//Has no effect on size
/*getHolder().setFixedSize(500,
500);*/
//Causes Eclipse to enter Debug mode. It crashes the program
//android.widget.FrameLayout.LayoutParams params = new android.widget.FrameLayout.LayoutParams(500, 500);
//setLayoutParams(params);
thread.start();
Log.d(TAG,"SurfaceView. surfaceCreated.");
}
}
我的一个约setFixedSize问题是单位做什么函数的参数代表什么?是int点还是像素?我正在阅读文档:
http://developer.android.com/reference/android/view/SurfaceHolder.html
但是它只是说setFixedSize的参数是整数。我还没有看到它在哪里描述了整数可能代表的单位。我是否试图设置一个糟糕的位置SurfaceView的大小 还是有一些其他问题?我正在开发针对API 19,API API最小为9.
P.S.我想我现在看到现在发生了什么setFixedSize()会改变画布的分辨率,但不会按照我打算做的那样改变LinearLayout中的宽度和高度。我在后面的代码中获得了屏幕宽度和高度,我打算做的是更改布局中存在的SurfaceView的宽度和高度。
P.P.S.我正计划在ScrollView中使用SurfaceView,但我现在正在阅读的方法可能无法实现。我更从这篇文章找出:
https://groups.google.com/forum/#!msg/android-developers/zkdnM0G225I/tt_FJGyOkB4J
谢谢
要查看'setFixedSize()'在行动,请参阅“硬件Scaler锻炼者“的活动Grafika(https://github.com/google/grafika)。快速演示在这里:https://www.youtube.com/watch?v=qpRaD-ij2xc – fadden 2014-09-04 15:41:15