Android:用另一个视图替换一个视图
我通常需要的是:通过单击按钮将一个视图替换为另一个视图(隐藏) 让我们深入了解细节: 我使用ViewPager,它由100个图像组成 ViewPager的布局Android:用另一个视图替换一个视图,android,android-layout,android-fragments,android-imageview,animated-gif,Android,Android Layout,Android Fragments,Android Imageview,Animated Gif,我通常需要的是:通过单击按钮将一个视图替换为另一个视图(隐藏) 让我们深入了解细节: 我使用ViewPager,它由100个图像组成 ViewPager的布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.andr
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#ffffff" >
</android.support.v4.view.ViewPager>
<ImageButton
android:id="@+id/imagePlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageRight"
android:layout_alignTop="@+id/imageList"
android:src="@drawable/list" />
</RelativeLayout>
图像布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="1dip"
android:background="#ffffff">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
它工作-没有问题。但我需要在viewpager中添加按钮,点击后,viewpager中的图像应更改为gif。它看起来像gif预览,在onclick play-gif开始播放之后
GIF的自定义布局:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageList"
android:layout_marginRight="28dp"
android:layout_toLeftOf="@+id/imageRight" >
<com.basv.gifmoviewview.widget.GifMovieView
android:id="@+id/gif1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
应该如何解决?点击按钮后打开另一个活动对我来说非常简单,但问题是在同一片段中播放gif
有什么想法吗?这里有个想法。使用“查看寻呼机”和“gif”进行布局,但gif可见性设置为“不可见”,使其最初在那里但不可见。但是,当有人点击按钮时,你应该将gif设置为可见,同时将“查看页面”更改为不可见或消失,以防你甚至不想看到它的初始边界,从而在代码中激活它 我只需将你的
com.basv.gifmoviewview.widget.gifmoviewview
添加到你的根RelativeLayout
(也许你需要将ViewPager
和gifmoviewview
包装在附加FrameLayout
中,并在需要时使用普通的setVisibility()
简单地显示/隐藏它
编辑
我想这不是手机内存使用的最佳解决方案
我很快地查看了一下,实际上没有太多的代码。因此,如果您担心内存使用问题,您可以在显示小部件之前动态创建它(并在隐藏后销毁),或者,由于我看不到“卸载”GIF的方法,您可以始终使用“1x1 px”空GIF,以确保您刚才停止显示的最后一个小部件不再占用宝贵的内存(如果不需要)。谢谢您的回复,我想这不是解决手机内存使用的最佳方案,但解决这个问题听起来不错。