通过翻译动画使ImageView与屏幕对齐

时间:2015-07-26 14:33:42

标签: android alignment android-animation translate-animation

ImageView大于屏幕宽度。我希望它向左移动(平移),因此它的右侧最终与其父级(屏幕)的右侧对齐。

.______.                         .______.            
|      |                         |      |
|...............         ................
.     image    .   -->   .    image     .
................         ................
|______|                         |______|

mv_anim.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
  android:toXDelta="-100%p"
  android:duration="50000"
  android:repeatMode="reverse"
  android:repeatCount="infinite">
</translate>
</set>

我想我可以通过代码将toXDleta设置为-(imageWidth - screenWidth)来实现。

但我想保持一切简单,根本不使用代码。有没有更简单的方法通过仅使用XML anim文件来实现这一目标?

1 个答案:

答案 0 :(得分:0)

您的ImageView不大于屏幕宽度。一切都被Window(又名屏幕)的界限所包含。 ImageView内的图像已关闭,因为它太大了。使用setScaleType(FIT_END)放置图片。

相关问题