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.
Related
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;
}
I have an adapter to a ListView is a list of ImageViews. I am using a stretch to make the image fil the imageview so I can take smaller images and make them larger on the screen, however the ImageView normally just uses wrap_content and this is an issue because the images just show up as their normal width and height. Is there any way I can set the height and width of a view before drawing it because as in this case I do not have control over the view after it has been drawn. Here is my aapter method:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
String currentImage = getItem(position);
ScaleType scaleType = ScaleType.FIT_CENTER;
float screenWidth = parent.getResources().getDisplayMetrics().widthPixels;
if (convertView == null) {
convertView = new ImageView(parent.getContext());
}
// WHAT I WOULD LIKE TO BE ABLE TO DO, but this returns null pointer exception
// convertView.getLayoutParams().width = (int) screenWidth;
// convertView.getLayoutParams().height = (int) ((float)(screenWidth/currentImage.getWidth())*currentImage.getHeight());
((ImageView) convertView).setScaleType(scaleType);
((ImageView) convertView).setImageBitmap(MainActivity.cache.getBitmap(currentImage));
return convertView;
}
How about something like someView.setHeight() and someView.setWidth()? Or someView.setLayoutParams()? You could add either of these to the overridden getView() callback and it should take care of your problem.
You could also Create a Custom View and override something like getMeasuredWidthAndState(). (I think that's one of the right methods, but I'm not one hundred percent sure.) You could create a width class variable and a height class variable that all instances of your custom ImageView would use. However, that might be a bit much if you just want to set the layout width and height though.
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;
}
I have Gallery control with ImageView as cell View. I need to have ImageView size equals the Gallery height. How can I do that? I tried to set height like this:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
FrameLayout retval = (FrameLayout) convertView;
ImageView imageView = (ImageView) retval.findViewById(R.id.image);
imageView.setLayoutParams(new FrameLayout.LayoutParams(parent.getHeight(), parent.getHeight()));
But first cell has height equals zero but next cells has right value.
Why not just set the imageView to fill the parent container through the params?
#Override
public View getView(int position, View convertView, ViewGroup parent) {
FrameLayout retval = (FrameLayout) convertView;
ImageView imageView = (ImageView) retval.findViewById(R.id.image);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
imageView.setLayoutParams(layoutParams);
That is, unless you want the width of the imageview to be equal to the height of the gallery. Then this would not work
I think you should set layoutParams on cell itself and let image view to scaleXY to the cell.
retval.setLayoutParams(new FrameLayout.LayoutParams(parent.getHeight(), parent.getHeight());
imageView.setScaleType(ScaleType.FIT_XY);
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/