首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >显示大于设备屏幕的图像,然后使用翻译动画浏览图片。

显示大于设备屏幕的图像,然后使用翻译动画浏览图片。
EN

Stack Overflow用户
提问于 2015-07-16 11:19:37
回答 1查看 643关注 0票数 0

现在,我知道如何使translateAnimation,以便通过图片,并显示在屏幕上。我不知道怎么做,就是把图片放在屏幕上,用这样的方式制作,这样它就不会按刻度类型进行缩放了。这样我就可以启动translateAnimation了。我看到了一些关于这方面的帖子,很多建议说我应该使用HorrizontalScrollView,这样才能把图片放得比设备屏幕大。但我需要让动画去思考它,而不是为了我能够移动的图片,所以在我看来,这可能不是一个完美的方式。你们还有其他建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-16 15:04:28

没有使用horrizontalScrollView,相反,强制整个布局的宽度为图片的大小,在其中设置一个RelativeLayout,与屏幕的大小,然后作出动画。

代码语言:javascript
复制
<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>

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

代码语言:javascript
复制
screenContainer.setLayoutParams(new RelativeLayout.LayoutParams(Math.round(Constants.screenWidth), Math.round(Constants.screenHeight)));

这是与父版本(背景图片的大小)匹配的ImageView的翻译:

代码语言:javascript
复制
 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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31452708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档