/**
* Demonstration of overlays placed on top of a SurfaceView.
* 展示可以在surface上添加view
*/
public class SurfaceViewOverlay extends Activity {
View mVictimContainer;
View mVictim1;
View mVictim2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.surface_view_overlay);
GLSurfaceView glSurfaceView =
(GLSurfaceView) findViewById(R.id.glsurfaceview);
glSurfaceView.setRenderer(new CubeRenderer(false));//绘制一个立方体,至于怎么绘制真的不是很清楚
// Find the views whose visibility will change
mVictimContainer = findViewById(R.id.hidecontainer);
mVictim1 = findViewById(R.id.hideme1);
mVictim1.setOnClickListener(new HideMeListener(mVictim1));
mVictim2 = findViewById(R.id.hideme2);
mVictim2.setOnClickListener(new HideMeListener(mVictim2));
// Find our buttons
Button visibleButton = (Button) findViewById(R.id.vis);
Button invisibleButton = (Button) findViewById(R.id.invis);
Button goneButton = (Button) findViewById(R.id.gone);
// Wire each button to a click listener
visibleButton.setOnClickListener(mVisibleListener);
invisibleButton.setOnClickListener(mInvisibleListener);
goneButton.setOnClickListener(mGoneListener);
}
@Override
protected void onResume() {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
super.onResume();
}
@Override
protected void onPause() {
// Ideally a game should implement onResume() and onPause()
// to take appropriate action when the activity looses focus
//游戏应该在resume 和pause中实现一些逻辑
super.onPause();
}
class HideMeListener implements OnClickListener {
final View mTarget;
HideMeListener(View target) {
mTarget = target;
}
public void onClick(View v) {
mTarget.setVisibility(View.INVISIBLE);
}
}
OnClickListener mVisibleListener = new OnClickListener() {
public void onClick(View v) {
mVictim1.setVisibility(View.VISIBLE);
mVictim2.setVisibility(View.VISIBLE);
mVictimContainer.setVisibility(View.VISIBLE);
}
};
OnClickListener mInvisibleListener = new OnClickListener() {
public void onClick(View v) {
mVictim1.setVisibility(View.INVISIBLE);
mVictim2.setVisibility(View.INVISIBLE);
mVictimContainer.setVisibility(View.INVISIBLE);
}
};
OnClickListener mGoneListener = new OnClickListener() {
public void onClick(View v) {
mVictim1.setVisibility(View.GONE);
mVictim2.setVisibility(View.GONE);
mVictimContainer.setVisibility(View.GONE);
}
};
}
<!-- Demonstrates changing view visibility. See corresponding Java code. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Here is where we put the SurfaceView, in a frame so that we can
stack other views on top of it. 我们可以把其他view 放到这个surfaceview上-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
<android.opengl.GLSurfaceView android:id="@+id/glsurfaceview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout android:id="@+id/hidecontainer"
android:orientation="vertical"
android:visibility="gone"
android:background="@drawable/translucent_background"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="@+id/hideme1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
android:text="@string/hide_me"/>
<Button android:id="@+id/hideme2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
android:text="@string/hide_me"/>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<Button android:id="@+id/vis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/visibility_1_vis"/>
<Button android:id="@+id/invis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/visibility_1_invis"/>
<Button android:id="@+id/gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/visibility_1_gone"/>
</LinearLayout>
</LinearLayout>