我创建了图库应用,然后我想通过添加一个名为ImageVIewZoom.jar的外部库来为我的图库中的图像添加缩放效果 从这个链接: https://github.com/kilaka/ImageViewZoom 我只将jar文件添加到我的项目中并非所有ImageViewZoom项目。
我按照这种方式添加库:
1- my libs - >右键单击 - >导入 - >文件系统 - > 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);
}
}
任何帮助都将受到高度赞赏。谢谢
答案 0 :(得分:0)
是的,这是添加.jar库的正确方法。您可以像在常规java中那样使用它(假设)。
ABCD a = new ABCD();
a.method();
在您的情况下,您的图书馆有一个示例代码。 See here.
此致