0

我创建画廊应用程序,然后我想通过添加一个名为的外部库来为我的画廊中的图像添加缩放效果:ImageVIewZoom.jar 从这个链接: https ://github.com/kilaka/ImageViewZoom 我只添加 jar 文件而不是全部ImageViewZoom 项目到我的项目。

我按照这种方式添加库:

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

2- myProject -> 右键单击​​ -> 属性 -> Java 构建路径 -> 库 -> 添加 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);
             }
            }

任何帮助将不胜感激。非常感谢

4

1 回答 1

0

是的,这是添加 .jar 库的正确方法。您可以像在常规 java 中一样使用它(假设)。

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

在您的情况下,您的库有一个示例代码。看这里。

问候,

于 2013-08-20T15:08:03.173 回答