picasso image size is coming up small - android

I have an imageview with the standard XML format: apply this xml to gridviewlist.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical" >
<ImageView
android:id="#+id/grid_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/grid_regular_image"
android:layout_centerHorizontal="true"
android:src="#drawable/none"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/grid_item_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/grid_item_image"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/default_numbers"
android:textColor="#color/grid_text"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
I am getting the image from an API and applying it to picasso. Like this:
Picasso.with(getContext().getApplicationContext()).load(pd.getImage()).placeholder(R.drawable.none).error(R.drawable.none).centerCrop().resize(230, 230).into(holder.image);
The images when displayed on GridView are coming really small? I am not sure why this is happening - this is happening even though the size is big?
Not sure what is wrong here? Can somebody help me fix this?
Thanks!

Same problem with me, problem exists in ImageAdapter class. Do not use .fit() and comment imageView.setLayoutParams, imageView.setScaleType and imageView.setPadding. Then it will be all good. Hope it helps
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
// imageView.setLayoutParams(new GridView.LayoutParams(185, 185));
// imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
String url = "http://image.tmdb.org/t/p/w780//nBNZadXqJSdt05SHLqgT0HuC5Gm.jpg";
//imageView.setImageResource(mThumbIds[position]);
Picasso.with(this.mContext)
.load(url)
// .fit()
//.resize(100, 100)
.into(imageView);
return imageView;
}

Related

Dimensions of the GridView cell is not changing

I dont know what is the problem in my code. I want to display some images in a GridView but the images being displayed are very small, and same is happening with the high resolutions images too. Please help. Thanks in Advance.
I dont know what to do. I am posting my code too.
activity_main.xml file
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<GridView
android:id="#+id/gridview_stickers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center">
</GridView>
gridview_items.xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:background="#000000">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/sticker"
android:scaleType="centerCrop"
/>
getView method of the AdapterClass
public View getView(int position, View convertView, ViewGroup parent) {
View imageView = convertView;
ImageView picture;
if(imageView == null) {
imageView = inflater.inflate(R.layout.gridview_items, parent, false);
imageView.setTag(R.id.sticker, imageView.findViewById(R.id.sticker));
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setPadding(8, 8, 8, 8);
}
picture = (ImageView)imageView.getTag(R.id.sticker);
picture.setImageBitmap(img.get(position).imageBitmap);
return imageView;
}
Finally I figured out myself. I changed the
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
to
imageView.setLayoutParams(new GridView.LayoutParams(300, 300));
and I got the desired results.

Gallery Image not fitting the screen in android

I am displaying a bunch of images in the Gallery View.
The layout is ,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<Gallery
android:id="#+id/gallery1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spacing="10dip" >
</Gallery>
<ImageView
android:id="#+id/imgfromWebUrl"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ImageView>
</LinearLayout>
and the custom adapter for loading images,
public View getView(int arg0, View paramView, ViewGroup arg2) {
Log.d("","custom Adapter5");
View localView;
if (paramView == null) {
localView = mInflater.inflate(R.layout.property_image_adapter, null);
} else {
localView = paramView;
}
ImageView imgfromWebUrl=(ImageView)localView.findViewById(R.id.imgfromWebUrl);
Log.d("", "pics[0]: "+pics);
imgfromWebUrl.setImageBitmap(pics[arg0]);
imgfromWebUrl.setScaleType(ImageView.ScaleType.FIT_XY);
imgfromWebUrl.setBackgroundResource(defaultItemBackground);
imgfromWebUrl.setLayoutParams(new Gallery.LayoutParams(200, 200));
return imgfromWebUrl;
}
currently my image is shown as,
My image is fit to the center part of the screen. but I want the image to fit full screen,like this image
Please help me out!!
Any help is Appreciated!!
Use this property android:scaleType="fitXY" Document for ImageView.ScaleType
Issue:
Image is fitting to the parent.but your gallery params are fixed of 200.
Solution:
kindly remove that line.
imgfromWebUrl.setLayoutParams(new Gallery.LayoutParams(200, 200));
and make this change in xml:
<Gallery
android:id="#+id/gallery1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:spacing="10dip" >
Configure the layout parameters like so:
i.setLayoutParams( new
Gallery.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT));

Design looks bigger when using minsdkversion 3

I created an app, it's finely working as what i want on minsdkversion="3". But other activities look even bigger than usual. If i change the minsdkversion="8" or something, the other activities looks as normal, but i didn't get the output i want.
Following is the code for gridview and imageview layout files:
activity_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="#+id/grid_View"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:horizontalSpacing="0dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:verticalSpacing="0dp"
android:gravity="center_horizontal"
android:clipChildren="true" >
</GridView>
</LinearLayout>
grid.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/image_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.05"/>
</LinearLayout>
MainActivity.java:
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;
if (convertView == null)
{
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
i = i+1;
imageView.setId(i);
Log.d("===== i value =====", String.valueOf(i));
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
else
{
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
What is the wrong with my code, what i have to change?
I have to show some toast when particular body part is pressed
Step #1: Display the body in an ImageView
Step #2: Override onTouchEvent() in your activity or fragment that is managing the ImageView
Step #3: Determine the body part based on the location of the touch event and the size of the ImageView, and display your Toast

Adjust GridView to all Screen Sizes

Im trying to implement a GridView as part of a image gallery. I followed the following example from the Android developer portal.
The tutorial seems to work for all screen sizes. As you can see below the proportions for a small and a large screen size are displayed correctly (on the left - small screen size, on the right - large screen size.
But now to my problem. When I want to implement exactly the same GridView within a LinearLayout from my Android Project - the correct proportions are gone - as shown by the images below. The pictures begin to overlap so forth and so on.
I am quite sure that this has something to with my LinearLayout which looks like the following.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget64"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/widget34"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#drawable/foto_detail_bg_cell_0"
>
<ImageView
android:id="#+id/flyer"
android:layout_width="100dp"
android:layout_height="80dp"
android:src="#drawable/icon"
android:scaleType="centerCrop"
/>
<LinearLayout
android:id="#+id/widget36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5px"
android:orientation="vertical">
<TextView
android:id="#+id/toptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beat.It"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#color/white"/>
<TextView
android:id="#+id/widget39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="http://www.google.at"
android:textColor="#color/white"/>
<LinearLayout
android:id="#+id/widget40"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/widget41"
android:layout_width="58dp"
android:layout_height="40dp"
android:src="#drawable/facebook_share"/>
<ImageView
android:id="#+id/widget42"
android:layout_width="58dp"
android:layout_height="40dp"
android:layout_marginLeft="1dp"
android:src="#drawable/photocount"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</LinearLayout>
The MAIN QUESTION:
The Layout XML used by the tutorial on the Android developer portal only uses the GridView alone, without a LinearLayout and and it is shown with correct proportions on each screen size. Why is that? And why does it not work properly when I nest the GridView in a Linear Layout like in my project?
SOLVED:
I solved this issue by editing the ImageAdapter of the GridView. I calculated the size of the generated image views - density independent.
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
//Calculation of ImageView Size - density independent.
//maybe you should do this calculation not exactly in this method but put is somewhere else.
Resources r = Resources.getSystem();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60, r.getDisplayMetrics());
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams((int)px, (int)px));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//imageView.setPadding(8, 8, 8, 8);
imageView.setBackgroundColor(Color.BLUE);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
To adjusting Gridview to screen size
In onCreate take rowHeight :
//Get root view
root = binding.root
// Or you can use findviewbyid(R.id.root)
view.onGlobalLayout {
rowHeight =
root.measuredHeight / currentPageNumberOfRow
fillView(appsList)
}
In adapter:
override fun getView(position: Int, ConvertView: View?, parent: ViewGroup?): View? {
var mConvertView = ConvertView
if (layoutInflater == null) {
layoutInflater =
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as
layoutInflater!!.inflate(R.layout.item_app_shortcut, null)
}
if (mConvertView == null) {
mConvertView =
layoutInflater!!.inflate(R.layout.item_child_launcher_app, null)
//Add this:
mConvertView.layoutParams = AbsListView.LayoutParams(GridView.AUTO_FIT, rowHeight)
}
Dont forget set row image:
android:layout_width="0dp"
android:layout_height="0dp"
To fit on screen

ClassCastException (Gallery + ImageView)

I have followed a tutorial to create a gallery with an imageview below it. All I want to do is place the gallery on the bottom and the imageview above it, but when I switch them around in the XML it gives me a ClassCastException.
Here is the XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/backrepeat"
android:orientation="vertical" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Gallery
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
That is the non-working version, but placing gallery above imageview works.
From log:
01-26 22:20:13.673: E/AndroidRuntime(349): Caused by: java.lang.ClassCastException: android.widget.ImageView
01-26 22:20:13.673: E/AndroidRuntime(349): at com.appinfluence.fanapp.v1.Photos.onCreate(Photos.java:36)
onCreate:
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(Photos.this));
imgView = (ImageView)findViewById(R.id.ImageView01);
imgView.setImageResource(mImageIds[0]);
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
imgView.setImageResource(mImageIds[position]);
}
});
}
Other helpful code:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mImageIds[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
Hey NickNelson Just now i got the solution to your problem, just clean the project it will work.
Sample screenshot
No need to use separate ImageView in the layout, Gallery will display the images. Remove the ImageView and check it..
edit
just clean the project . ( as yugandhar said.)
Kindly try this XML for the layout section:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical">
<ImageView android:layout_alignParentTop="true"
android:id="#+id/ImageView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/antartica1"/>
<Gallery
android:id="#+id/Gallery01"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>

Categories

Resources