如何在所有活动之上制作菜单栏(如GameCIH)

时间:2013-11-11 15:14:19

标签: android android-layout android-intent

我在android中的新功能。 这是交易。我希望让我的活动像GameCih菜单栏(就像所有活动一样,我可以绕过应用程序,做我想做的任何事情,菜单栏仍在上面) 但我想做的与GameCIH并不完全相同。我想要音乐播放器,所以我可以播放歌曲,显示专辑封面,并通过触摸在屏幕上移动播放器菜单。 这是我的主要活动:

public class MainActivity extends Activity implements OnTouchListener{
RelativeLayout rel;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);

    rel = (RelativeLayout) findViewById(R.id.myactivity);
    rel.setOnTouchListener(this);
    this.setFinishOnTouchOutside(false);
    this.getWindow().setBackgroundDrawable(new ColorDrawable(0));
      Window dialogWindow = this.getWindow();

      // Make the dialog possible to be outside touch
      dialogWindow.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
      WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
      dialogWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

      Button btn =(Button)findViewById(R.id.button1);
      btn.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }

      });
      Thread th = new Thread(){
          public void run (){

            try {
                while(true){
                Thread.sleep(10000);
                try{
                    Intent i=new Intent(getApplicationContext(),MainActivity.class);
                    //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                    startActivity(i);

                }catch(Exception ex){
                    Log.d("X",ex.getMessage());
                }
                }
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

          }
      };
      th.start();

}


@Override
public void onBackPressed() {
    // Do Here what ever you want do on back press;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
    // TODO Auto-generated method stub

if(rel==arg0){
     switch(arg1.getAction())
        {
        case MotionEvent.ACTION_MOVE:
          {
              WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
                layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
                layoutParams.x = ((int) arg1.getRawX()-400);
                layoutParams.y = ((int) arg1.getRawY()-200);
                this.getWindow().setAttributes(layoutParams);
          return true;
          }
        case MotionEvent.ACTION_UP:
          {
              WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
                layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
                layoutParams.x = ((int) arg1.getRawX()-400);
                layoutParams.y = ((int) arg1.getRawY()-200);
                this.getWindow().setAttributes(layoutParams);

          return true;
          }
        case MotionEvent.ACTION_DOWN:
          {
              WindowManager.LayoutParams layoutParams = this.getWindow().getAttributes();
                layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
                layoutParams.x = ((int) arg1.getRawX()-400);
                layoutParams.y = ((int) arg1.getRawY()-200);
                this.getWindow().setAttributes(layoutParams);
          return true;
          }
        }

  }


    return false;
}


  }

和xml

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myactivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<Button
    android:id="@+id/button1"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/textView1"
    android:text="End" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button1"
    android:layout_alignBottom="@+id/button1"
    android:layout_alignLeft="@+id/textView1"
    android:ems="10" >

    <requestFocus />
</EditText>

</RelativeLayout>

清单:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dialogtest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.dialogtest.MainActivity"
            android:label="@string/app_name" 
            android:theme="@android:style/Theme.Holo.Dialog">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    </manifest>

gamecih

http://i.stack.imgur.com/RgivT.jpg

我的应用

http://i.stack.imgur.com/VvPcP.jpg

我的问题是:

  • 1我无法获得活动
  • 2可以触摸外面,但在某些应用中我触摸什么都不会发生
  • 3我使用startActivity(i);来获取forground上的活动,但它会重新启动并且相同的问题在2

非常感谢您的帮助

0 个答案:

没有答案