1
我使用horizontalscrollView將一組圖像作爲幻燈片放映。我有5張可繪製的圖像,我可以將圖像從右向左移動,但在某些手機中,它只是滾動到第3張圖像並重新開始滾動,並且在某些手機中,它只是停止滾動,直到到達右側圖像的末尾。請幫忙 !!這是我使用的代碼:在自動滾動horizontalscrolview中顯示圖像
public void getScrollMaxAmount(){
int actualWidth = (horizontalOuterLayout.getMeasuredWidth()-200);
scrollMax = actualWidth;
}
public void startAutoScrolling(){
if (scrollTimer == null) {
scrollTimer=new Timer();
final Runnable Timer_Tick=new Runnable() {
public void run() {
moveScrollView();
}
};
if(scrollerSchedule != null){
scrollerSchedule.cancel();
scrollerSchedule = null;
}
scrollerSchedule = new TimerTask(){
@Override
public void run(){
runOnUiThread(Timer_Tick);
}
};
scrollTimer.schedule(scrollerSchedule, 50, 50);
}
}
public void moveScrollView(){
scrollPos= (int) (hsv2.getScrollX() + 1.0);
if(scrollPos >= scrollMax){
scrollPos=0;
}
hsv2.scrollTo(scrollPos, 0);
}
public void addImagesToView(){
for (int i=0;i<imageNameArray.length;i++){
Log.d("imagname",String.valueOf(imageNameArray.length));
final ImageView imageButton = new ImageView(this);
int imageResourceId = getResources().getIdentifier(imageNameArray[i], "drawable",getPackageName());
Drawable image = this.getResources().getDrawable(imageResourceId);
imageButton.setBackgroundDrawable(image);
imageButton.setTag(i);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(90,LayoutParams.WRAP_CONTENT);
//params.setMargins(0, 25, 0, 25);
imageButton.setLayoutParams(params);
horizontalOuterLayout.addView(imageButton);
}
我試圖把512代替,但它仍然沒有工作。與200是滾動高達最後的圖像和停止有.. – addy123