3

I have problem translating very large picture in Android. What I would like is my picture's height to be set screen's height and to show the rest of width not changing image's ratio. Since my image is very wide, not whole would be shown for first, but it would with translation, I would slowly move it over x axis.

I think there must be simple way to do this, but I'm struggling already 6 hours watching all question here and other, trying to find where I'm mistaking because I can't show my picture like that it's shown just as much as it can be shown - height set to full screen's height and width just as much as it fit and then to show other part of picture's width as it's translating.

My code:

import android.os.Bundle;
...

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); 

ImageView imageView = (ImageView) findViewById (R.id.background);
ObjectAnimator mover = ObjectAnimator.ofFloat(imageView, "translationX", 0, 1000f);
mover.setDuration(10000);     
mover.start();
}
}

and simple layout:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/background"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:src="@drawable/background"
        android:scaleType="centerCrop">

The thing with scaleType with centerCrop and center is that they same do both - they maintain image's ratio and height is screen's height, but the image is cut and when I make animation, immediately starts to go white screen as if there is no more width of picture. centerInside is not helping either.

Can you please help me? I already lost so many hours on this. I would be really thankful.

4

1 回答 1

1

这里的一个选择是将您的ImageView内部放置在ScrollView. 完成此操作后,您可以创建一个计时器,例如TimerTask每隔几毫秒在屏幕上缓慢滚动图像的计时器。

您可以在此处了解有关计时器的更多信息:Android 计时器?如何?

一旦设置了计时器,只需调用TimerTaskscrollView.scrollBy(10, 10)scrollView.scrollTo(10, 10)从 TimerTask 中移动ScrollView它,然后再翻译您附加的ImageView.

于 2013-07-25T01:15:10.130 回答