【问题标题】:resize gif animation in android在android中调整gif动画大小
【发布时间】:2013-08-17 15:26:52
【问题描述】:

我想调整 gif 动画的大小,以便我的 1 个按钮适合屏幕。我正在使用 WebView 进行 gif 动画。当我插入图像按钮时,它不会显示。请帮忙。

<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"; xmlns:tools="schemas.android.com/tools"; 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".Activity_B" > 

    <ImageButton android:id="@+id/imageButton1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentTop="true" 
        android:src="@drawable/back" /> 

</RelativeLayout>

【问题讨论】:

  • 请输入代码,以便我们了解您的尝试。
  • 更新你的代码和android中的Webview不支持gif动画。你需要为gif动画编写自己的实现
  • android中的WebView支持gif动画。我已经做了。而且它甚至不需要任何imageview,我们可以直接把gif动画的路径和它做。我只想在屏幕上显示一个图像按钮,但我猜屏幕已被 gif 动画完全占据,所以任何人都可以告诉我如何将图像按钮放在动画的前面,以便它引人注目和可点击..
  • schemas.android.com/apk/res/android" xmlns:tools="schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Activity_B" >

标签: android resize gif


【解决方案1】:

你在哪里定义你的 WebView?看看这是否适合你:

<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"; xmlns:tools="schemas.android.com/tools"; 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".Activity_B" > 

    <ImageButton android:id="@+id/imageButton1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentTop="true" 
        android:src="@drawable/back" /> 

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageButton1" />

</RelativeLayout>

编辑 1:

假设带有RelativeLayoutImageButton 的布局文件称为mainLayout.xml。 执行以下操作:

View mainView = getLayoutInflater().inflate(R.layout.mainLayout, null);

RelativeLayout rlContainer = (RelativeLayout) mainView.findViewById(R.id.rlContainer);

GIFWebView view = new GIFWebView (this, "file:///android_asset/imageedit_ball.gif");

RelativeLayout.LayoutParams wvParams = new RelativeLayout.LayoutParams(
                                              RelativeLayout.LayoutParams.MATCH_PARENT,
                                              RelativeLayout.LayoutParams.MATCH_PARENT);

wvParams.addRule(RelativeLayout.BELOW, R.id.imageButton1);

rlContainer.addView(view, wvParams);

setContentView(mainView);

给你的 RelativeLayout 一个 id:

android:id="@+id/rlContainer"

<RelativeLayout xmlns:android="schemas.android.com/apk/res/android"; xmlns:tools="schemas.android.com/tools"; 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".Activity_B"
    android:id="@+id/rlContainer" > 

    <ImageButton android:id="@+id/imageButton1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentTop="true" 
        android:src="@drawable/back" /> 

</RelativeLayout>

【讨论】:

  • 我不需要像这样插入 webview。 gif 动画正在播放。但我无法显示我需要在动画上使用的按钮。我试过了,但没有用。
  • @Meghs 您能否发布在布局中添加WebView 的方式和位置?你能把那部分代码贴出来吗?
  • GIFWebView view = new GIFWebView (this, "file:///android_asset/imageedit_ball.gif");设置内容视图(视图);其中 GIFWebView 是一个扩展 WebView 的类。 public class GIFWebView extends WebView { public GIFWebView(Context context, String path) { super(context);加载网址(路径); } }
  • @Meghs 看看上面的 Edit 1。它会解决你的问题。
  • @Meghs 在seContentView(mainView); 之前添加ImageButton imageButton1 = (ImageButton) mainView.findViewById(R.id.imageButton1); imageButton1.setOnClickListener(new OnClickListener() {.....})
【解决方案2】:

请添加相对布局,然后将第一个按钮和第二个网页视图放入相对布局。

【讨论】:

  • 我尝试了所有可能的组合,但无法解决问题。
  • 上面已经写好了代码。一样的。谁能告诉我如何在 gif 动画的前面添加一个按钮?
猜你喜欢
  • 2018-04-18
  • 2011-11-01
  • 2012-09-07
  • 1970-01-01
  • 2011-02-23
  • 2012-04-16
  • 2013-08-28
  • 2011-08-09
  • 2011-08-31
相关资源
最近更新 更多