2013-08-20 31 views
-1

创建画廊的应用程序,然后我想通过添加名为外部库添加在我的画廊缩放效果图片:ImageVIewZoom.jar 从这个链接: https://github.com/kilaka/ImageViewZoom 我只将不是所有ImageViewZoom项目的jar文件都添加到我的项目中。如何使用库JAR导入后现有项目

我添加库这种方式如下:

1 - 我的库 - >右键 - >导入 - >文件系统 - > ImageViewZoom.jar

2- myProject的 - >右键 - >属性 - > Java Build Path - > Libraries - > Add Jar - > ImageViewZoom.jar。

现在jar文件已经在我的项目中如何在我的画廊类中使用或使用jar类,这样我最终在运行我的应用程序时,我的图像将具有缩放效果。

是新来的Android和第一次使用我的项目内外部库,

编辑: 请问我需要添加我的画廊类的内部或进口里面的一些代码,如果是的话怎么会是。

这是我的画廊类,实际上它不是我的代码,但我在这里创建了stackoverflow并使用它来形成无限的画廊。

@SuppressWarnings("deprecation") 
public class DayGallery extends Activity { 
TextView tv; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // Set the layout to use 
    setContentView(R.layout.main); 

    InfiniteGallery galleryOne = (InfiniteGallery) findViewById(R.id.galleryOne); 
    galleryOne.setAdapter(initializeImages()); 
    galleryOne.setSelection(galleryOne.getCount()/2); 
      }   


private InfiniteGalleryAdapter initializeImages() { 
    InfiniteGalleryAdapter galleryAdapter = null; 

    String day = getIntent().getStringExtra("dayname"); 


    if(day.equalsIgnoreCase("london")){ 
     int[] tempimages = { R.drawable.ic_launcher, R.drawable.ic_launcher,R.drawable.ic_launcher }; 
     String[] name = { " 1"," 2", " 3"}; 

     galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); } 

    else if(day.equalsIgnoreCase("paris")){ 
     int[] tempimages = { R.drawable.ic_launcher, R.drawable.ic_launcher,R.drawable.ic_launcher }; 
     String[] name = { "4","5", "6"}; 

     galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); } 

    else if(day.equalsIgnoreCase("rom")){ 
     int[] tempimages = { R.drawable.ic_launcher, R.drawable.ic_launcher,R.drawable.ic_launcher }; 
     String[] name = { "7","8", "9"}; 

     galleryAdapter=new InfiniteGalleryAdapter(this, tempimages, name); } 


       } 

    } 

    return galleryAdapter; 
      } 
      } 


class InfiniteGalleryAdapter extends BaseAdapter { 
private Context mContext; 
private int[] images; 
private String[] name; 
public InfiniteGalleryAdapter(Context c, int[] imageIds,String[] names) { 
    this.mContext = c; 
    images = imageIds; 
    name=names; 
    inflater = (LayoutInflater)mContext.getSystemService (Context.LAYOUT_INFLATER_SERVICE); } 

public int getCount() { 
    return Integer.MAX_VALUE; 
       } 

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

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

private LayoutInflater inflater=null; 


public class ViewHolder{ 
    public TextView text; 
    public ImageView image; 
        } 


public View getView(int position, View convertView, ViewGroup parent) { 
    ImageView i = getImageView(); 

    int itemPos = (position % images.length); 

    try { i.setImageResource(images[itemPos]); ((BitmapDrawable) i.getDrawable()).setAntiAlias(true); 
       } 

    catch (OutOfMemoryError e) { Log.e("InfiniteGalleryAdapter", "Out of memory creating imageview. Using empty view.", e); 
          } 

    View vi=convertView; 
    ViewHolder holder; 
    if(convertView==null){ 
     vi = inflater.inflate(R.layout.gallery_items, null); 
     holder=new ViewHolder(); holder.text=(TextView)vi.findViewById(R.id.textView1); 
     holder.image=(ImageView)vi.findViewById(R.id.image); 
     vi.setTag(holder); } 

    else holder=(ViewHolder)vi.getTag(); 
    holder.text.setText(name[itemPos]); 

    final int stub_id=images[itemPos]; 
    holder.image.setImageResource(stub_id); 

    return vi; 
       } 

private ImageView getImageView() { 

    ImageView i = new ImageView(mContext); 

    return i; 
     } 
      } 

@SuppressWarnings("deprecation") 
class InfiniteGallery extends Gallery { 

public InfiniteGallery(Context context) { 
    super(context); 
    init(); 
       } 

public InfiniteGallery(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    init(); 
       } 

public InfiniteGallery(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    init(); 
        } 

private void init(){ 
    // These are just to make it look pretty 
    setSpacing(50); 
    setHorizontalFadingEdgeEnabled(false); 
      } 
      } 

任何帮助将高度赞赏.thanks很多

回答

0

是的,这是正确的方式来增加的.jar库。你可以像使用普通java一样使用它(假设)。

ABCD a = new ABCD(); 
a.method(); 

就你而言,你的库有一个示例代码。 See here.

问候,

+0

我是否需要添加一些代码,我的画廊类的内部或进口里面,如果是的话怎么会是。谢谢 – androidqq6