I need to add full width image in the notification for my application.
I do it by sending the URL in the json payload, load the bitmap and on successful image loading I show the notification.
My question is what is the best optimum resolution of the Image
Please help!
Thanks in advance.
The width of your image should be equal to the width of the screen as the width of the dropdown notification bar will be the same.
In order to do that you need to do this:
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
After doing this you can set the value of int width to your image.
Related
Im trying to change an image lager than the screen so that the image partly(boundary parts) gets out of the screen. The purpose Im doing this is to make the whole screen filled with the image. I tried simply changing the height and width bigger than the height and width of screen which I got but it didn't work well. I used code below to get the size of the screen.
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
val height = displayMetrics.heightPixels
val width = displayMetrics.widthPixels
How should I do for this?
In the xml match the height and width of the image to parent and change the scaleType attribute to centerCrop -> android:scaleType="centerCrop"
If you want to fill the image to entire screen like a zoomed view, I think you can try image loading libraries like Picasso or Glide to crop the image to fit it inside the layout and also it will handle the caching for large sized images.
For Picasso you can try something like this
Picasso.with(this).load(R.drawable.image).centerCrop().into(imageView);
As seen in this image:
I have a rounded rectangle that is the size of 1082 x 1796, and I used getWindowManager().getDefaultDisplay() to get and print the pixel values of the screen as seen in the circle bottom left. However, when I draw this bitmap, this happens:
Is the screen size different from the getDefaultDisplay() method? How do I fix this?
I think your shape is seen by the system as a 9patch. It use the first and last lines/columns in order to know how to resize the image in order to display it consistently.
That's why there is a 2px difference in width and height. I think you can correct it by modifying the png and removing the first and last lines/columns, or just use another way to draw the image. Maybe using another format (jpg ? bmp ?) for the image could do the job. I'm not sure.
you can do that with calculation to fit all screen devices based on width and height of the device screen:
DisplayMetrics dm = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = width * imageHeight / imageWidth;
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
I have an ImageView with a dynamic src, and I want to display it, only if there is enough place to show all of it without scaling it.
How should I handle this?
you need to get the image size and screen size then check to see if its larger before displaying
If you want the the display dimensions in pixels you can use
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
If you don't have access to an activity to call getWindowManager on. You can use:
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
For the use case you're describing however a margin/padding in the layout seems more appropriate.
then do
if (ImageView.getDrawable().getIntrinsicHeight() > height || ImageView.getDrawable().getIntrinsicWidth() >width){
//dont display image
}
coppied and compiled from two post
Get screen dimensions in pixels
and
Trying to get the display size of an image in an ImageView
imageView.setScaleType(ScaleType.FIT_XY);
I need to obtain the screen resolution, width & height, how do I do that?
Solution:
Display d = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
width = d.getWidth();
height = d.getHeight();
Display d=Display.getInstance();
int width = d.getDisplayWidth();
int height = d.getDisplayHeight();
According to http://forums.java.net/jive/message.jspa?messageID=479230
or possibly
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
http://www.coderanch.com/t/435390/Android/Mobile/screen-size-at-run-time
PLEASE first ask yourself why you need to do this. You very probably don't. If it is to do anything based on the screen size (layout etc) this will return you the wrong information, since it is telling you about the physical resolution of the screen, not taking into account anything like the status bar, window decorations, etc. Even if you are running your app as full-screen, in some cases there may be parts of the screen that are used for system UI that you can't get rid of but will be included in the numbers returned by Display.
The correct thing to do is adjust for the size your view gets during layout, such as when its onSizeChanged() is called.
So i am trying to get the screen size of the Moto Droid on my application. on my Create, i am using the Service windowManager to get the default display.
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
When i set it i get width of 320 and height 570. that looks wrong, it should be 320x480.
i want to place a 300x50 image on the bottom of the screen on any device (actually) so normally i would get the height of the screen and minus the image height so it places it on a view. but since i am getting 570 for some reason, i have to scroll down to see the image. why is it getting the wrong screen size and is there another more accurate way of getting the size. Thank you
Layout code goes as follows
linearOut = new LinearLayout(this);
linear = new LinearLayout(this);
linear.setOrientation(LinearLayout.VERTICAL);
scroll = new ScrollView(this);
linearOut.addView(scroll);
scroll.addView(linear);
linear.addView(text);
linear.addView(bbottom.getViewGroup());
setContentView(linearOut);
try this::
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
I think i got it. so the info above shows full screen viewable. so that does include the status bar. Is there a way to see the height of the status bar? i am not sure if all android devices have the same pixel height for the status bar.