Android: UI elements on canvas layer

How do I set some UI elements on the canvas (at the top)?

I have a simple touch game, and its graphics are placed on the custom view and canvas. However, since my full screen panel is in setcontentview(), I can't add any UI items, such as ProgressBar or logo. I want the whole canvas layer to be visible and some objects (ProgressBar, logo) "float" on it

Main courses:

public class GameClass extends Activity implements OnGestureListener {

Panel panel;

public void onCreate(Bundle savedInstance) {
  super.onCreate(savedInstance);

  panel = new Panel(this, 1, 2);
  setContentView(Panel);
  ...
}

Group:

public class Panel extends View {   

  public Panel(Context context, int Var1, int Var2) {
    super(context);
    ...
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    ...
  }
}

As shown in the code, touch is processed in gameclass, and changes in animation are processed in panel

Or maybe... Can you start a new transparent activity using the progress bar and buttons to overwrite the buttons on the activity and the objects on the underlying activity? I can turn off all layers through the transparent activity button (transparent activity, panel, gameclass). Complex?: d

resolvent:

I do have the same problem. That's how I solve it

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.game);

    drawView = new DrawView(this);
    drawView.requestFocus();
    LinearLayout upper = (LinearLayout) findViewById(R.id.LinearLayout01);
    upper.addView(drawView);
    ImageButton menu = (ImageButton) findViewById(R.id.ImageButton01);
    menu.setOnClickListener(new OnClickListener()
    {           
        @Override
        public void onClick(View v)
        {
            finish();
        }
    });
    ImageButton reset = (ImageButton) findViewById(R.id.ImageButton02);
    reset.setOnClickListener(new OnClickListener()
    {           
        @Override
        public void onClick(View v)
        {
            drawView.resetGame();
        }
    });
}

Instead of setting the contentview as a panel, add it to the LinearLayout in my game.xml. Here is my

<?xml version="1.0" encoding="utf-8"?><RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@drawable/game_background">
<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="350dip" />
<LinearLayout
    android:id="@+id/LinearLayout02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/LinearLayout01">
    <ImageButton
        android:id="@+id/ImageButton01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/menu"></ImageButton>
    <ImageButton
        android:id="@+id/ImageButton02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/reset"></ImageButton>
</LinearLayout>
<LinearLayout
    android:layout_below="@+id/LinearLayout01"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:id="@+id/layout_ad"
    android:layout_height="wrap_content" />

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>