use*_*313 4 android android-imageview android-scrollview
在我的活动中,我只有一个ImageView.在其中,src是比屏幕大很多的图片.我希望图片从左到右缓慢滚动,直到它到达照片的右边缘,然后开始向左滚动,直到达到左边距.然后重新开始.我需要它在一个单独的线程中发生,这样手机就不会在发生这种情况时冻结.

我怎样才能做到这一点?是否有一个小部件默认执行此操作?
更新的代码 //布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mylinear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="@drawable/rainforest" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
//和活动
public class MainActivity extends Activity {
Animation _translateAnimation;
RelativeLayout _relativeLoading = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_translateAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, -100f, TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 0f);
_translateAnimation.setDuration(5000);
_translateAnimation.setRepeatCount(-1);
_translateAnimation.setRepeatMode(Animation.REVERSE); // REVERSE
_translateAnimation.setInterpolator(new LinearInterpolator());
_relativeLoading = (RelativeLayout) findViewById(R.id.mylinear);
_relativeLoading.startAnimation(_translateAnimation);
}
Run Code Online (Sandbox Code Playgroud)
但它没有了.我的意思是,滚动从左到右,将图片"推"到左边,并在ImageView下显示白色背景.
此外,这应该在一个线程或什么?我需要能够以某种方式退出这个"滚动"活动,而不使用"后退"按钮.我想要一个ImageView顶部的按钮(按钮应保持静止)和onClick它应该启动另一个Intent
似乎ImageView中的图片被裁剪为适合屏幕内部.我怎么能克服这个?
所以,我的问题的解决方案在这里(对于所有新的Android开发人员,像我一样,他们的应用可能需要这个):
public class MainActivity extends Activity {
Animation _translateAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_translateAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, -300f, TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 0f);
_translateAnimation.setDuration(8000);
_translateAnimation.setRepeatCount(-1);
_translateAnimation.setRepeatMode(Animation.REVERSE); // REVERSE
_translateAnimation.setInterpolator(new LinearInterpolator());
ImageView img = (ImageView) findViewById(R.id.img);
img.startAnimation(_translateAnimation);
}
}
Run Code Online (Sandbox Code Playgroud)
和布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/global_relative"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/img"
android:layout_width="600dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@drawable/rainforest"
android:scaleType="center"
android:src="@drawable/rainforest613x490" >
</ImageView>
</ScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
只要确保你的形象是大/高到足以适应屏幕,并且是(+ 300dp)比屏幕宽度要宽(或调整上面的代码).
快乐的编码;)
| 归档时间: |
|
| 查看次数: |
6760 次 |
| 最近记录: |