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);
}
Related
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);
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
I'm currently trying to set the height of an ImageView, placed as ListView header, but i'm always getting an NullPointerExpection in imageHeaderView.getLayoutParams. Here's my code:
ImageView imageHeaderView = new ImageView(this);
imageHeaderView.setImageBitmap(BitmapFactory.decodeResource(getResources(),
R.drawable.deckblatt));
imageHeaderView.setScaleType(ScaleType.CENTER_CROP);
imageHeaderView.getLayoutParams().height = 50;
myList.addHeaderView(imageHeaderView);
Is it not possible to get/set the layoutParams, when used in a ListView header?
What else can i do to set the height of my ImageView?
Best regards
try this--->
ImageView imageHeaderView = new ImageView(this);
imageHeaderView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.deckblatt));
imageHeaderView.setScaleType(ScaleType.CENTER_CROP);
imageHeaderView.setLayoutParams(new AbsListView.LayoutParams(100, 100));
myList.addHeaderView(imageHeaderView);
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));
For some reason, when I create a bitmap from an image in asset, it does not display fullscreen. When I take an image from drawable, resId, the image shows fullscreen. Why is this?
//the image is not fullscreen
ImageView iv = new ImageView(getBaseContext());
iv.setImageBitmap(bitmapFileFromAssetorSD);
//this makes the image fullscreen
//iv.setBackgroundResource(resId);
iv.setLayoutParams(
new LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT
)
);
Try setting the appropriate ImageView.ScaleType
ImageView.setScaleType(ImageView.ScaleType.CENTER_CROP)