现在,我知道如何使translateAnimation,以便通过图片,并显示在屏幕上。我不知道怎么做,就是把图片放在屏幕上,用这样的方式制作,这样它就不会按刻度类型进行缩放了。这样我就可以启动translateAnimation了。我看到了一些关于这方面的帖子,很多建议说我应该使用HorrizontalScrollView,这样才能把图片放得比设备屏幕大。但我需要让动画去思考它,而不是为了我能够移动的图片,所以在我看来,这可能不是一个完美的方式。你们还有其他建议吗?
发布于 2015-07-16 15:04:28
没有使用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);https://stackoverflow.com/questions/31452708
复制相似问题