我希望像Marquee效果一样连续滚动列表视图,这就是我需要为列表视图添加的内容。
答案 0 :(得分:-1)
请参阅此 post,或者您可以使用某个适配器EndlessAdapter或this one。
MarqueeLayout.java
import android.content.Context;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
public class MarqueeLayout extends FrameLayout {
private Animation animation;
public MarqueeLayout(Context context) {
super(context);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, +1f,
Animation.RELATIVE_TO_SELF, -1f,
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0f
);
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.RESTART);
}
public void setDuration(int durationMillis) {
animation.setDuration(durationMillis);
}
public void startAnimation() {
startAnimation(animation);
}
}
和 MarqueeLayoutActivity.java
import android.app.Activity;
public class MarqueeLayoutActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*List view code here*/
MarqueeLayout marqueeLayout = new MarqueeLayout(this);
marqueeLayout.setDuration(10000);
marqueeLayout.addView(listView);
marqueeLayout.startAnimation();
setContentView(marqueeLayout);
}
}
希望它有所帮助。