如何使一个子视图apear在Android的现有活动之上?视图、个子、Android、apear

2023-09-05 05:15:50 作者:爺,創造神話

我写一个应用程序,允许用户访问他们的企业语音邮件系统。语音邮件显示在列表视图,并且当选择了一个给他们的菜单。当用户选择收听我想一个小的媒体播放器弹出在现有的ListView顶部的屏幕的底部(类似于软键盘是如何出现在需要的时候,然后就离开,当它完成)。

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).

选项?

推荐答案

将所有的意见(即:你的ListView)到RelativeLayout的把你的媒体播放器布置在底部的元素,并设置其知名度水涨船高

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);

  }
}