安卓:替换另一个

问题描述:

一个观点我需要一般:更换(隐藏)一个视图与另一个通过点击一个按钮安卓:替换另一个

让我们深入的细节: 我用ViewPager,其中包括100个图像。

布局ViewPager

图片

<?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> 

它的工作原理布​​局的

<?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> 

- 没有问题。但是我需要添加按钮到viewpager,并且在viewpager中点击图像后应该更改为gif。它看起来像gifs预览和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

任何想法?

我想简单地增加你的com.basv.gifmoviewview.widget.GifMovieView某处根RelativeLayout(也许你可能需要额外的FrameLayout包裹都ViewPagerGifMovieView)和简单的显示/隐藏它使用普通的setVisibility()需要的时候。

编辑

我想这是不是手机的内存使用

我赶紧看了到sources,而且也没有太多的代码真的是最好的解决方案。所以,如果你打扰内存使用情况,你总是可以动态地创建widget,然后显示它(并且一旦隐藏就销毁),或者因为我看不到“卸载”GIF的方法,你总是可以使用“1x1 px”空Gif来确保最后一个如果不需要,你只是停止显示不再占用宝贵的内存。

+0

感谢您的回复,我想这不是手机内存使用的最佳解决方案,但解决这个问题听起来不错。 – tadvas

+0

见编辑answre –

这是一个想法。使用view pager和gif进行布局,但将gif可见性设置为不可见,以便最初在那里但不可见。但是当有人点击按钮时,您应该将该gif置于代码中,将其设置为可见,同时将视图寻呼机更改为不可见,或者如果您不希望它的初始边界存在,则将其删除!