2011-04-17 63 views
2

我真的需要幫助。 我有一個漫畫書類型的獨立應用程序。圖像翻轉使用onfling手勢來回翻頁 但是,我非常需要能夠縮放每個圖像/面板。 這是一個擴展庫: 請幫我添加縮放功能到這段代碼! 謝謝 請不要把我同這裏的東西已經張貼在計算器我讀這一切並沒有幫助我迄今爲止...Android縮放圖庫幫助

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.content.res.TypedArray; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.BaseAdapter; 
import android.widget.Gallery.LayoutParams; 
import android.widget.ImageView; 
import android.widget.Toast; 
@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mygallery gallery = (mygallery) findViewById(R.id.thisgallery); 

     gallery.setAdapter(new AddImgAdp(this)); 

     gallery.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> parent, View v, int position, long id) { 

       Toast.makeText(main.this, "Page " + position, Toast.LENGTH_SHORT).show(); 
      } 

     }); 

    } 

    public class AddImgAdp extends BaseAdapter { 
     int GalItemBg; 
     private Context cont; 


     private Integer[] Imgid = { 
       R.drawable.s1, 
       R.drawable.s1a, 
       R.drawable.s1b, 
       R.drawable.s1b1, 
       R.drawable.s1b2, 
       R.drawable.s1b3, 
       R.drawable.s1c, 
       R.drawable.s1s, 
       R.drawable.s2, 
       R.drawable.s3, 
       R.drawable.s4, 
       R.drawable.s5, 
       R.drawable.s6, 
       R.drawable.s7, 
       R.drawable.s8, 
       R.drawable.s9, 
       R.drawable.s10, 
       R.drawable.s11, 
       R.drawable.s12, 
       R.drawable.s13, 
       R.drawable.s14, 
       R.drawable.s15, 
       R.drawable.s16, 
       R.drawable.s17, 
       R.drawable.s18, 
       R.drawable.s19, 
       R.drawable.s20, 
       R.drawable.s21, 
       R.drawable.s22, 
       R.drawable.s23, 
       R.drawable.s24, 
       R.drawable.s25, 
       R.drawable.s26, 
       R.drawable.s27, 
       R.drawable.s28, 
       R.drawable.s29, 
       R.drawable.s30, 
       R.drawable.s31, 
       R.drawable.s32, 
       R.drawable.s33, 
       R.drawable.s34, 
       R.drawable.s35, 
       R.drawable.s36, 
       R.drawable.s37, 
       R.drawable.s38, 
       R.drawable.s39, 
       R.drawable.s40, 
       R.drawable.s41, 
       R.drawable.s42, 
       R.drawable.s43, 
       R.drawable.s44, 
       R.drawable.s45, 
       R.drawable.s46, 
       R.drawable.s47, 
       R.drawable.s48, 
       R.drawable.s49, 
       R.drawable.s50, 
       R.drawable.s51, 
       R.drawable.s52, 
       R.drawable.s53, 
       R.drawable.s54, 
       R.drawable.s55, 
       R.drawable.s56, 
       R.drawable.s57, 
       R.drawable.s58, 
       R.drawable.s59, 
       R.drawable.s60, 
       R.drawable.s61, 
       R.drawable.s62, 
       R.drawable.s63, 
       R.drawable.s64, 
       R.drawable.s65, 
       R.drawable.s66, 
       R.drawable.s67, 
       R.drawable.s68, 
       R.drawable.s69, 
       R.drawable.s70, 
       R.drawable.s71, 
       R.drawable.s72, 
       R.drawable.s73, 
       R.drawable.s74, 
       R.drawable.s75, 
       R.drawable.s76, 
       R.drawable.s77, 
       R.drawable.s78, 
       R.drawable.s79, 
       R.drawable.s80, 
       R.drawable.s81, 
       R.drawable.s82, 
       R.drawable.s83, 
       R.drawable.s84, 
       R.drawable.s85, 
       R.drawable.s86, 
       R.drawable.s87, 
       R.drawable.s88, 
       R.drawable.s89, 
       R.drawable.s90, 
       R.drawable.s91, 
       R.drawable.s92, 
       R.drawable.s93, 
       R.drawable.s94, 
       R.drawable.s95, 
       R.drawable.s96, 
       R.drawable.s97, 
       R.drawable.s98, 
       R.drawable.s99, 
       R.drawable.s100, 
       R.drawable.s101, 
       R.drawable.s102, 
       R.drawable.s103, 
       R.drawable.s104, 
       R.drawable.s105, 
       R.drawable.s106, 
       R.drawable.s107, 
       R.drawable.s108, 
       R.drawable.s109, 
       R.drawable.s110, 
       R.drawable.s111, 
       R.drawable.s112, 
       R.drawable.s113, 
       R.drawable.s114, 
       R.drawable.s115, 
       R.drawable.s116, 
       R.drawable.s117, 
       R.drawable.s118, 
       R.drawable.s119, 
       R.drawable.s120, 
       R.drawable.s121, 
       R.drawable.s122, 
       R.drawable.s123, 
       R.drawable.s124, 
       R.drawable.s125, 
       R.drawable.s126, 
       R.drawable.s127, 
       R.drawable.s128, 
       R.drawable.s129, 
       R.drawable.s130, 
       R.drawable.s131, 
       R.drawable.s132, 
       R.drawable.s133, 
       R.drawable.s134, 
       R.drawable.s135, 
       R.drawable.s136, 
       R.drawable.s137, 
       R.drawable.s138, 
       R.drawable.s139, 
       R.drawable.s140, 
       R.drawable.s141, 
       R.drawable.s142, 
       R.drawable.s143, 
       R.drawable.s144, 
       R.drawable.s145, 
       R.drawable.s146, 
       R.drawable.s147, 
       R.drawable.s148}; 

     public AddImgAdp(Context c) { 
      cont = c; 
      TypedArray typArray = obtainStyledAttributes(R.styleable.Gallery1); 
      GalItemBg = typArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0); 
      typArray.recycle(); 
     } 

     public int getCount() { 
      return Imgid.length; 
     } 

     public Object getItem(int position) { 
      return position; 
     } 

     public long getItemId(int position) { 
      return position; 
     } 

     public View getView(int position, View convertView, ViewGroup parent) { 
      ImageView imgView = new ImageView(cont); 

      imgView.setImageResource(Imgid[position]); 

      imgView.setScaleType(ImageView.ScaleType.FIT_XY); 
      imgView.setBackgroundResource(0x0106000d); 
      imgView.setLayoutParams(new mygallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

      return imgView; 
     } 
    } 
} 

和onfling覆蓋:

import android.content.Context; 
import android.util.AttributeSet; 
import android.view.KeyEvent; 
import android.view.MotionEvent; 
import android.widget.Gallery; 




public class mygallery extends Gallery { 

    public mygallery(Context ctx, AttributeSet attrSet) { 
     super(ctx, attrSet); 
     // TODO Auto-generated constructor stub 
    } 

    private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2){ 
      return e2.getX() > e1.getX(); 
     } 

    @Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ 
     int kEvent; 
     if(isScrollingLeft(e1, e2)){ //Check if scrolling left 
     kEvent = KeyEvent.KEYCODE_DPAD_LEFT; 
     } 
     else{ //Otherwise scrolling right 
     kEvent = KeyEvent.KEYCODE_DPAD_RIGHT; 
     } 
     onKeyDown(kEvent, null); 
     return true; 
    } 

} 
+0

我在後(這裏)一個示例代碼的鏈接[1],希望它可以幫助 [1]:http://stackoverflow.com/questions/10268806/android-gallery-with-捏變焦 – 2012-04-22 14:33:16

+0

你有沒有想出任何解決方案。如果你想分享它.. @ wintermuteai – 2012-08-03 07:23:14

回答

0

您可以使用android ScaleAnimation類來實現縮放效果。但事實是,動畫並不會真正改變它所應用的視圖的大小/位置,這是一個很大的問題,因爲您應用動畫的視圖的命中將始終保持不變,等等。但是沒有其他方法可以實現縮放效果AFAIK(至少在3.0之前的android版本中)。

+0

另外我怎樣才能加載每個圖像的web視圖,使變焦控制已經在那裏?請參閱我的代碼和發佈幫助? – Wintermuteai1 2011-04-17 22:04:17