小编mir*_*ira的帖子

Android翻译动画 - 使用AnimationListener将View永久移动到新位置

我有android翻译动画.我有一个随机生成位置的ImageView(next1,next2).我每隔3秒就调用一次虚空.它生成视图的新位置,然后制作动画并将视图移动到目标位置.翻译动画已实现AnimationListener.动画完成后,我将View永久移动到新位置(在OnAnimationEnd中).我的问题是动画位置与设置layoutParams位置不对应.当动画结束时,它会跳转到一个新位置,大约50-100像素.我认为位置应该是相同的,因为我在两种情况下都使用相同的值(next1,next2).请问您能找到找到溶剂的方法吗?在这里绘制情况

 FrameLayout.LayoutParams pozice_motyl = (FrameLayout.LayoutParams)  pozadi_motyl.getLayoutParams();    
            TranslateAnimation anim = new TranslateAnimation(Animation.ABSOLUTE,pozice_motyl.leftMargin, Animation.ABSOLUTE, next1, Animation.ABSOLUTE, pozice_motyl.topMargin, Animation.ABSOLUTE, next2);
            anim.setDuration(1000);
            anim.setFillAfter(true);
            anim.setFillEnabled(true);

            anim.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {




                    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100);

                    layoutParams.leftMargin = (int)(next1);
                    layoutParams.topMargin = (int)(next2);
                    pozadi_motyl.setLayoutParams(layoutParams);

                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

            pozadi_motyl.startAnimation(anim);
Run Code Online (Sandbox Code Playgroud)

这是XML布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:id="@+id/pozadi0"
    android:gravity="center_vertical"
    android:layout_gravity="center_vertical"          
    android:background="@drawable/pozadi2"
    >



<LinearLayout
android:id="@+id/pozadi_motyl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >

  <ImageView android:id="@+id/obrazek_motyl"
             android:src="@drawable/motyl"
             android:layout_width="100dip" …
Run Code Online (Sandbox Code Playgroud)

android android-animation translate-animation

33
推荐指数
3
解决办法
10万
查看次数

Android使用intent限制时间记录

使用意图时如何限制录制?我试过这段代码:

 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
 intent.putExtra("android.intent.extra.durationLimit",5);    
 startActivityForResult(intent,RQS_RECORDING);
Run Code Online (Sandbox Code Playgroud)

当我录制视频时,这部分代码工作正常.时间从5倒数到0,5秒后录音自动停止.但是当我录制声音时,这个有限的时间不起作用.为什么?

Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
intent.putExtra("android.intent.extra.durationLimit", 5);
startActivityForResult(intent, RQS_RECORDING);
Run Code Online (Sandbox Code Playgroud)

当我录制声音时,为什么这个时间限制5秒不起作用?

time android record limit android-intent

15
推荐指数
2
解决办法
9228
查看次数

如何使用Intent捕获视频并设置记录的路径并限制录制时间

我使用基于意图录制视频的示例

Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
Run Code Online (Sandbox Code Playgroud)

对于我使用的时间限制:intent.putExtra("android.intent.extra.durationLimit", 5); 此记录5秒,然后自动停止.

我使用了URL中的示例:http: //android-er.blogspot.cz/2011/04/start-video-recording-using.html 这个例子对我来说很有意思,因为我可以在所有设备上运行并且易于实现.

是否可以设置保存录制视频的路径?简单地说,我需要将视频保存到指定文件"myrecordedvideo.mp4"到指定文件夹,并且需要视频才能有5秒钟.是否可以通过此Intent轻松实现?

video android capture filepath android-intent

5
推荐指数
1
解决办法
9225
查看次数

Android MediaPlayer 在一段时间后停止播放

onclick ImageButton 后有小游戏播放短声音。但是在触摸 10 次 MediaPlayer 后,短时间内停止播放声音。一段时间后它再次播放声音。当我查看 LogCat 控制台时,它显示错误:E/MediaPlayer(19584): error (1, -2147483648)

请你能告诉我找到解决这个问题的解决方案的方法吗?为什么 MediaPlayer 给我错误?

我使用这部分代码来播放声音:

public void playAudio () {
    try {
        mediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.trefa);
    mediaPlayer.setLooping(false);
    mediaPlayer.start();
    mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
            public void onCompletion(MediaPlayer arg0) {

            }
    });
    } catch (Exception e) {
    Log.e("beep", "error: " + e.getMessage(), e);
    }
    }
Run Code Online (Sandbox Code Playgroud)

android playback media-player

2
推荐指数
1
解决办法
3166
查看次数