我的 Activity 中有播放按钮和视频 View 。在 xml 中,我将按钮设为不可见。在 java 代码中,我试图让它可见。
在视频 View 的 OnPreparedListener
方法中,我试图让它可见。但它没有变得可见。下面是我的代码。
vvVideos.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
btnPlay.setVisibility(Button.VISIBLE);
}
});
XML 文件::
<RelativeLayout
android:id="@+id/bottomll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<VideoView
android:id="@+id/videoView"
android:layout_width="fill_parent"
android:layout_height="150dp"/>
<Button
android:id="@+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/play"
android:visibility="gone"/>
</RelativeLayout>
最佳答案
而不是这个::
vvVideos.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
btnPlay.setVisibility(Button.VISIBLE);
}
});
使用这个并尝试::
vvVideos.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
btnPlay.setVisibility(View.VISIBLE);
}
});
希望这有帮助:)
关于android - 如何使按钮在视频 View 中可见 "OnPreparedListener"方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17088961/