Imageview not showing all image - android

Hello i am showing images in android app using gallery. I am having problem in displaying images. Some images are displayed some are not.
My adapter code is as follows:
ImageView iv;
LinearLayout layoutnew = new LinearLayout(getApplicationContext());
layoutnew.setOrientation(LinearLayout.VERTICAL);
if (convertView == null)
{
iv = new ImageView(ctx);
iv.setBackgroundDrawable(m_docs_ids[arg0]);
iv.setScaleType(ImageView.ScaleType.FIT_XY);
int temp =(int) (height/1.7f);
int temp_y = (int) ((3*temp)/2.0f);
iv.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT ));
}
else
{
iv = (ImageView) convertView;
}
TextView tv = new TextView(ctx);
// tv.setText(m_docs.get(arg0).DocPath);
tv.setTextColor(0xFFFFFFFF);
tv.setPadding(0, 15, 0, 0);
tv.setTag(arg0);
tv.setTextSize(18);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT ));
tv.setGravity(Gravity.CENTER);
layoutnew.addView(iv);
layoutnew.addView(tv);
return layoutnew;
m_docs_id is a list of drawable type. i have debug it and found that it is getting correct entry. gallery is showing black for images which are not shown.
I found put that pictures placed in DCIM folders are not shown. all other images are shown

you initialize the imageViewlike this iv = new ImageView(ctx);
you should initilize the imageView like this iv = (ImageView) findViewById(R.id.mImageView);

Finally i got my problem solved. Issue was not in DCIM folder, issue was in size. The pictures taken from cell phone camera is very high and gallery was not getting those images. I set size in drawables of photo with mobile screen size. Now its running f9

Related

how to removing programmatically composed pictures

I create imageview programmatically. but after I finish game this imageview cannot close how can i close, remove this imageview.
if I use this code image.setImageResource(0); just last image closing but I want to close all image
final ImageView image = new ImageView(getContext());
image.setImageResource(id);
image.setLayoutParams(params);
layout.addView(image);
Great!!! This is my solution..
` final ImageView [] image = new ImageView[5];
`
image[userartis]=new ImageView(getActivity());
image[userartis].setImageResource(id); image[userartis].setLayoutParams(params);
layout.addView(image[userartis]);
for (int i=0;i<=userartis;i++){
image[i].setVisibility(View.GONE);
}

Covering android ImageView

While I was working on my project I found that the image couldn't cover the whole space of ImageView completely! this is the first time that i have got a problem like this.
Here is my code :
int ImgId = getResources().getIdentifier("test1", "drawable", getPackageName());
Photo=new LinearLayout(this);
lp = new LinearLayout.LayoutParams(Width/2,Width/2);
Photo.setLayoutParams(lp);
Photo.setOrientation(LinearLayout.VERTICAL);
Photo.setBackgroundColor(getResources().getColor(R.color.mainGreen));
Img = new ImageView(this);
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
Img.setLayoutParams(lp);
Img.setBackgroundColor(getResources().getColor(R.color.Black));
Img.setImageResource(ImgId);
Photo.addView(Img);
I have used this piece of code many times before. The image covered the ImageView's space but now its not working well!
What is the problem? How can I cover ImageView completely?
Img.setBackground(ImgId);
//Img.setImageResource(ImgId);
or
Img.setBackground(ImgId);
Img.setScaleType(ImageView.ScaleType.FIT_XY);
Img.setImageResource(ImgId);
Just add ScaleType to the ImageView to specify the behavior
Img.setScaleType(ImageView.ScaleType.CENTER_CROP);

Adding ImageView leads to the black screen

I have the problem: when you try to add ImageView the LinearLayout, some images are not loaded and the program stops with a black screen. Picture JPG or PNG there is no difference. Tried to change the size of 100x100px to 1080x1920. If I replace the picture on another then everything is fine, but I need this picture. I put the exception to this code, but in the logcat nothing, i.e. the exception does not occur.
Please help me. Thank you.
for (int i = 0, lenI = anims.length; i < lenI; i++ ) {
try {
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
//add image
ImageView imageView = new ImageView(this);
linearLayout.addView(imageView);
int resId = getResources().getIdentifier("ru.romston.testprog:drawable/"+pics[i], null, null);
imageView.setImageResource(resId);
imageView.setMaxHeight(100);
imageView.setMaxWidth(100);
imageView.setPadding(5,5,5,5);
imageView.setAdjustViewBounds(true);
//label
TextView textView = new TextView(this);
linearLayout.addView(textView);
textView.setText(anims[i]);
layout.addView(linearLayout);
} catch (Exception e) {
Log.e(TAG, "read data: error!" + e.getMessage(), e);
}
}
I think the image is of higher resolution/size that Android rendering system fails to scale it into height and width of 100. Try with same image after changing the image size/resolution.
Please correct if wrong.
ImageViews have a resolution limit based on OpenGL. If the bitmap or image passes this limit resolution, it shows a black screen and throws no error.
You can retrieve this limit by querying OpenGL:
int[] maxSize = new int[1];
GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
See this answer for more details

setImageUri on ImageView doesnt work

I am trying to make a picture with my app but it doesn't work.
I'm implementing a function to record a picture with my app, the result of this is a URI.
This URI I have in my activity, with this I try to show the user the recorded picture, to realize this I use from the imageview the method setImageUri ... but it doesn't work for me.
The thing I'm confused about, the imageview exist, in the screen I see the dimension.
In this case, the code that I have implemented
ImageView imgView = new ImageView(activityContext);
imgView.setImageURI(Uri.parse(captureImg.toString()));
mainFrame.addView(imgView, 100, 100);
another solutions:
Drawable d = Drawable.createFromPath(captureImg.toString());
ImageView imgView = new ImageView(activityContext);
imgView.setImageDrawable(d);
mainFrame.addView(imgView, 100, 100);
This both doesn't work for me, I have to try to use any solutions with Bitmap but this doesn't work me too.
Greets
Please make sure your "UI code" (imgView.setImageDrawable(d);) run on UIthread
Take this for reference: http://www.vogella.com/articles/AndroidPerformance/article.html
Try as:
ImageView imgView = new ImageView(activityContext);
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
imgView.setLayoutParams(vp);
imgView.setMaxHeight(100);
imgView.setMaxWidth(100);
imgView.setImageURI(Uri.parse(captureImg.toString()));
mainFrame.addView(imgView);
you are not adding LayoutParams to dynamically created ImageView
---Try this---
ImageView imgView = new ImageView(activityContext);
imgView.setImageURI(Uri.parse(captureImg.toString()));
mainFrame.addView(imgView, new LinearLayout.LayoutParams(200,200));

android how to give width n height to an image programatically

In my activity i am creating a Imageview dynamically. Every time it fetch the image from server create an imageview and set that image.
All images size also not same , so i want to put all images in a particular size.
But its not working. Here is my code bellow,
ImageView imageView = new ImageView(getActivity());
imageView.setImageResource(mContent);
imageView.setPadding(20, 20, 20, 20);
imageView.setMaxWidth(400);
imageView.setMaxHeight(400);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(imageView);
Simply do this,
imageview.getLayoutParams().height=100;
imageview.getLayoutParams().width=100;

Categories

Resources