Android设置glsurfaceview的高度
我想用自定义高度设置GLSURFACHEVIEW的高度。 我希望宽度和高度相同。 使用android:layout\u width=“fill\u parent”。 如何使屏幕的宽度=高度=宽度Android设置glsurfaceview的高度,android,height,glsurfaceview,Android,Height,Glsurfaceview,我想用自定义高度设置GLSURFACHEVIEW的高度。 我希望宽度和高度相同。 使用android:layout\u width=“fill\u parent”。 如何使屏幕的宽度=高度=宽度 非常感谢您可以使用view.getLayoutParams().height=view.getMeasuredWidth()以编程方式设置高度问题是这必须在第一次绘制视图后进行,否则measuredWidth将返回零。(假设您使用的是openGL),可以相当肯定的是,在调用渲染器类中的onDraw时,它
非常感谢您可以使用
view.getLayoutParams().height=view.getMeasuredWidth()以编程方式设置高度
问题是这必须在第一次绘制视图后进行,否则measuredWidth
将返回零。(假设您使用的是openGL),可以相当肯定的是,在调用渲染器类中的onDraw
时,它肯定是在屏幕上绘制的。但是,您必须在GL线程(调用onDraw
)和(主)UI线程之间传递消息,这是唯一允许更改视图宽度/高度等的线程。您需要覆盖onMeasure,并将setMeasuredDimension的两个参数设置为接收到的宽度,如下所示:
class TouchSurfaceView extends GLSurfaceView {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = View.MeasureSpec.getSize(widthMeasureSpec);
this.setMeasuredDimension(width, width);
}
...
布局如下:
...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_gravity="top"
>
<se.company.test.TouchSurfaceView android:id="@+id/glSurface"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
...
。。。
...