2013-01-12 30 views
1

我只是找到一個全屏幕庫實現的解決方案,但我無法獲得代碼工作。也許任何人都可以幫助我。全屏庫代碼

我需要一個沒有縮略圖庫的全屏圖像切換器,我可以在用手指滑動圖片之間切換。

我得到了以下錯誤: firstActivity不能被解析爲一個 型slide_in_right不能得到解決或無法在現場 slide_out_left不能得到解決或無法在現場

我非常新到Android編碼: )

請幫我

package com.example.prog; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnTouchListener; 
import android.view.ViewGroup; 
import android.view.animation.AnimationUtils; 
import android.widget.ImageSwitcher; 
import android.widget.ImageView; 
import android.widget.ViewSwitcher.ViewFactory; 
import android.util.Log; 
import android.view.MotionEvent; 
import android.widget.ViewSwitcher; 
import android.widget.Gallery; 
import android.widget.Gallery.LayoutParams; 
import android.widget.AdapterView; 
import android.widget.BaseAdapter; 
import android.view.Window; 
import android.content.Context; 



public class l2_AltInvestActivity extends Activity implements ViewFactory { 


ImageSwitcher imageSwitcher; 

Integer[] imageList = { 
R.drawable.fr_l1_01, 
R.drawable.fr_l1_02, 
R.drawable.fr_l1_03, 
R.drawable.fr_l1_04, 
R.drawable.fr_l1_05 
}; 

int curIndex=0; 
int downX, upX; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.mmenutest); 

    imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher); 
    imageSwitcher.setFactory(this); 
    imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in)); 
    imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out)); 
    imageSwitcher.setImageResource(imageList[curIndex]); 
    imageSwitcher.setOnTouchListener(new OnTouchListener() { 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      if (event.getAction() == MotionEvent.ACTION_DOWN) { 
       downX = (int) event.getX(); 
       Log.i("event.getX()", " downX " + downX); 
       return true; 
      } 
      else if (event.getAction() == MotionEvent.ACTION_UP) { 
       upX = (int) event.getX(); 
       Log.i("event.getX()", " upX " + downX); 

       if (upX - downX > 100) { 
        imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(firstActivity.this,android.R.anim.slide_in_left)); 
        imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(firstActivity.this,android.R.anim.slide_out_right)); 
        //curIndex current image index in array viewed by user 
        curIndex--; 
        if (curIndex < 0) { 
         curIndex = 5; //maximum 
        } 

        //imageList :-image list array 
        imageSwitcher.setImageResource(imageList[curIndex]); 
        //GalleryActivity.this.setTitle(curIndex); 
       } 
       else if (downX -upX > -100) { 
        curIndex++; 
        if (curIndex > 4) { 
         curIndex = 0; 
        } 
        imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.slide_in_right)); 
        imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.slide_out_left)); 
        imageSwitcher.setImageResource(imageList[curIndex]); 
        //GalleryActivity.this.setTitle(curIndex); 
       } 
      return true; 
      } 
     return false; 
     } 
    }); 
} //END onCreate 

@Override 
public View makeView() { 
    ImageView i = new ImageView(this); 
    i.setScaleType(ImageView.ScaleType.FIT_CENTER); 
    i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 
    i.setBackgroundColor(0xFF000000); 
    return i; 
} //END makeView 

} // END Class 

回答

1

使用當前活動上下文來訪問資源,而不是任何其他活動,如當前點播e您正試圖通過傳遞firstActivity.this來訪問動畫資源。

imageSwitcher.setInAnimation(AnimationUtils. 
     loadAnimation(l2_AltInvestActivity.this,android.R.anim.slide_in_left)); 
imageSwitcher.setOutAnimation(AnimationUtils. 
     loadAnimation(l2_AltInvestActivity.this,android.R.anim.slide_out_right)); 

使用l2_AltInvestActivity.this代替firstActivity.this

+0

感謝,這對我很有幫助。但是你有沒有關於slite_out信息的想法? slide_in_right slide_out_left – user1966046

+0

@ user1966046:最受歡迎的朋友。 –

+0

@ user1966046:如果此答案解決了您當前的問題,請將其標記爲答案,對於任何其他問題,如果您提出一個新問題以獲得良好且快速的答案,那麼該答案很好 –