【问题标题】:Display a image larger than the device screen, and then go through the picture with a translation animation显示大于设备屏幕的图像,然后用翻译动画浏览图片
【发布时间】:2015-07-16 11:19:37
【问题描述】:

现在我知道如何制作 translateAnimation,以便浏览图片并将其显示在屏幕上。 我不知道该怎么做,将图片放在屏幕上,并以这样的方式制作,使其不会按比例类型缩放。所以我可以启动 translateAnimation。 我看到了一些关于这个的帖子,很多建议说我应该使用 HorrizontalScrollView,以便放置比设备屏幕更大的图片。但是我需要制作动画,而不是让我能够移动图片,所以在我看来这可能不是完美的方式。 大家还有什么建议吗?

【问题讨论】:

    标签: android imageview wallpaper screen-size translate-animation


    【解决方案1】:

    没有使用horrizontalScrollView,而是将整个布局的宽度强制为图片大小,在里面设置一个RelativeLayout,和屏幕大小一样,然后制作动画。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="1103dp"
    android:layout_height="736dp"
    android:background="@color/white">
    
    <ImageView
        android:id="@+id/background"
        android:visibility="invisible"
        android:src="@drawable/story1"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    
    <RelativeLayout
        android:id="@+id/screen_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    -----------------CODE inside relative layout for normal page--------
    </RelativeLayout>
    
    </RelativeLayout>
    

    然后在我的代码中,我为我的屏幕容器设置屏幕宽度和高度(包含除了要翻译的背景图片之外的所有内容):

    screenContainer.setLayoutParams(new RelativeLayout.LayoutParams(Math.round(Constants.screenWidth), Math.round(Constants.screenHeight)));
    

    这是我对匹配父级的ImageView的翻译(背景图片的大小):

     TranslateAnimation translateBackground = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_PARENT,from,
                TranslateAnimation.RELATIVE_TO_PARENT,-0.5f,
                TranslateAnimation.RELATIVE_TO_PARENT,0.0f,
                TranslateAnimation.RELATIVE_TO_PARENT,0.0f);
        translateBackground.setDuration(15000);
        background.setVisibility(View.VISIBLE);
        background.startAnimation(translateBackground);
    

    【讨论】:

      猜你喜欢
      • 2011-09-20
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 2021-06-03
      • 2016-05-22
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多