how to find the last Image of Gallery in android - android

I am working on Gallery View in android. I am sliding the Images in Gallery View , I need to check the last Image of the Gallery images. After reaching at the end of the Gallery Images if user swipe more than I have to move to another activity . I am confused about how to detect the End of the Gallery Images.
public View getView(int index, View view, ViewGroup viewGroup) {
ImageView img = new ImageView(mContext);
img.setImageResource(CopyRightPagesActivity.typedImgsCopyRight.getResourceId(index, 1));
img.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
img.setScaleType(ImageView.ScaleType.FIT_XY);
return img;
}

Related

Cannot resolve method decodeFile in android studio

I am newbie to native android development. I am working on android studio. I have 3 tabs. One is for map second is for camera to take pictures and 3rd is for pictures in which all taken were to be shown. I have implemented map and camera, for viewing image i am following this tutorial. Here in a class i added Bitmap image = Bitmap image = decodeFile(_filePaths.get(position), imageWidth, imageWidth);
But it's showing me error Cannot Resolve method decodeFile. I have searched for it and couldn't find any solution for it.
Below is my code
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(_activity);
} else {
imageView = (ImageView) convertView;
}
// get screen dimensions
Bitmap image = decodeFile(_filePaths.get(position), imageWidth, imageWidth);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(imageWidth,
imageWidth));
imageView.setImageBitmap(image);
// image view click listener
imageView.setOnClickListener(new OnImageClickListener(position));
return imageView;
}
Any help would be highly appreciated.
it is custom method defined in the class (in the tutorial you should have missed to copy a method named decodeFile() ) check again ..
Use this
Bitmap image = BitmapFactory.decodeFile(_filePaths.get(position), imageWidth, imageWidth);

Load image without cropping in imageview android

I created the app to display images in carousel view. I loaded images into imageview which is in another xml layout file & set them in carousel view contain in main xml layout file.
Here how i load imaged into image view
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.showsmain, null);
ImageView image=(ImageView)vi.findViewById(R.id.imageView1);
//LinearLayout rlayout=(LinearLayout)vi.findViewById(R.id.layout);
image.setImageResource(R.drawable.black);
orgWidth = image.getDrawable().getIntrinsicWidth();
orgHeight = image.getDrawable().getIntrinsicHeight();
imageLoader.DisplayImage(data[position], image);
imageLoader.getDimension(widthScreen, heightScreen);
LinearLayout lhome=(LinearLayout)((Activity) activity).findViewById(R.id.layouthome);
// LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
// widthScreen,heightScreen/3);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
widthScreen,heightScreen/3);
params.width=orgWidth;
image.setLayoutParams(params);
image.setScaleType(ImageView.ScaleType.FIT_XY);
return vi;
}
orgWidth is a width of imageview. widthscreen is a width of screen where app is run. below you can see how image is loaded in carousel view.
![enter image description here][1]
here you see image is crop. I want to load the images without crop....
I try to handle this during three days with three question in stackoverflow.
If anyone can know the answer .....help me
here I also give my carousel layout xml file....
<com.touchmenotapps.carousel.simple.HorizontalCarouselLayout
android:id="#+id/carousel_layout_event"
android:layout_width="600dp"
android:layout_height="500dp"
android:layout_above="#+id/relativeLayout1"
android:layout_alignTop="#+id/carousel_layout" >
</com.touchmenotapps.carousel.simple.HorizontalCarouselLayout>
After you make your ImageView, call this:
image.setScaleType(ScaleType.CENTER_INSIDE);
Then, instead of cropping, your image will scale to fit the View bounds with a maintained aspect ratio.

Gallery View not filling complete screen when get created

I have created horizontal gallery view using this Tutorial
But when gallery is created it starts from half of the screen, below screen shot
I want that when gallery view starts it should start from left of screen not center.
Thanks
Better way to escape, mark the focus from second item.
Try to use in xml--
android:gravity="left"
in your getView function you can set the image that should be centered. So you can set the last image as below
imageView.setImageResource(mImageIds[position]);
Something I did
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mImageIds[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}

Gallery with image and text

I'm trying to build a gallery with text below the image but although I've followed every response founded in here I've yet to accomplish my objective.
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.VERTICAL);
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(150, 150));
TextView tv = new TextView(ll.getContext());
tv.setTag(mText[position]);
tv.setText(mText[position]);
tv.setLayoutParams(new Gallery.LayoutParams(48, 48));
ll.addView(tv);
// The preferred Gallery item background
//i.setBackgroundResource(mGalleryItemBackground);
return ll;
//return i;
}
I don't know why (and maybe it's the dumbest thing) but my images don't appear:)
I believe you forgot to add the image view to the linear layout, simply add:
ll.addView(i);
Also you are not recycling the convertView which could cause problems unless you have very few images and little to no scrolling of the grid.
You should check if convertView is null and if it is not simply change the text and image of the existing convertView.
Here is a good example for a custom grid view:
http://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-select-multiple/

ImageGallery and ImageGrid in android

I have created an image gallery in android , now whenever i will click on image on a gallery then that particular image will get added into Grid View.
my layout has image gallery on top and image grid in bottom (so i have used LinerLayout Vertical )
so can anyone tell me how to achieve this in android ?
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new Gallerydapter(this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
ImageView imageView = new ImageView(PhotoGallery.this);
imageView.setLayoutParams(new GridView.LayoutParams(45, 45));
imageView.setAdjustViewBounds(false);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
imageView.setImageResource(mImageIds[position]);
mGrid.addView(imageView);
}
I have used the above code to add images in grid view , is this the efficient code ? i mean is this code gonna generate running out of memory error

Categories

Resources