简体   繁体   中英

How do I make a sub view apear on top of an existing activity in Android?

I am writing an app that allows a user to access their corporate voice mail system. the voice mails are displayed in a list view and when one is selected they are given a menu. when the user selects "listen" i would like a small media player to pop up at the bottom of the screen on top of the existing ListView (similar to how the soft keyboard comes up when needed and then goes away when its done).

options?

Add all your views (ie: your ListView) to a RelativeLayout put your media players layout elements at the bottom and set their visibility to gone.

<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >

  <ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

  <RelativeLayout
    android:id="@+id/mediaPopup"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" 
    android:visibility="gone"
    >
    <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="I am a media player!"
      />
  </RelativeLayout>

</RelativeLayout>

Then in your activity class you can animate on your view like this:

function void showMediaPlayer() {

  if(mMediaPopUp.getVisibility() == View.GONE) {

    // Show Media Player
    TranslateAnimation mAnimUp = 
      new TranslateAnimation(
        Animation.RELATIVE_TO_SELF, 
        0, 
        Animation.RELATIVE_TO_SELF, 
        0, 
        Animation.RELATIVE_TO_SELF, 
        -(mMediaPopUp.getHeight()), 
        Animation.RELATIVE_TO_SELF, 
        0);

    mAnimUp.setStartOffset(500);
    mAnimUp.setDuration(500);

    mMediaPopUp.setVisibility(View.VISIBLE);
    mMediaPopUp.setAnimation(mAnimUp);

  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM