hi.
I have a problem with android layout.
gif is what designer want I make. and I made things successfully but menu.
png(alpha image) is our menu image. last 40px of height is want to display.
and if user touch that 40px of image is coming down just like gif image shows.
I don't have any idea how can make that. Constraint Layout doesn't support negative value.
ps. png is based on 1080 height resolution. but I will add dynamic resolution calcaulator function, so don't mind about 40px. 40 just mean 'want to display part of imageview'
SOLVED.
make imageview in constraint layout xml and inflate it.
then you can set x,y location programmatically.
I confused it. because when I tried it, It doesn't work. you must know view has relative location.
Related
I'm using Android Studio, and have created an ImageView in activity_mail.xml. The layout width and height are set to "match_parent". The scaleType is set to "center" and the source image is 70x70 pixels. When I run the app in the emulator the Image appears on the screen larger than 70x70 pixels. I mean it takes up more than 70x70 pixels on the screen of the phone. I don't know why it's doing this. The app is exclusively in Landscape mode, that might be relevant. Forgive me if I have included extraneous details, I genuinely don't know what information would be relevant to include. I intend to make it so that the image takes up 70x70 pixels on the screen of the phone. What is causing the unintended result, and how could I fix it?
change ScaleType, maybe fit_center instead of just center + android:adjustViewBounds="true” will fit your purposes... another way is to create ImageView with wrap_content sizes placed in some container (e.g. RelativeLayout) with match_parent sizes
also check this visual guide for ScaleType
note that 70px image will be big on devices with HD resolution and significantly smaller on those with e.g. full HD. you should have few versions of your image in proper density buckets (mdpi, hdpi etc.) or just download proper size if your image comes frome some API, so then you can say that you have image with 70dp dimension, not 70px
I am currently working on creating a custom progress bar and have so far managed to get the correct image I want to display, however I am trying to customise it so that it fill the white space within my drawable from bottom to top (bottom being 0 and top 100). I am using xml layouts.
I am not entirely sure if this is possible, the image I am trying to fill is;
Any guidance as to whether this is possible or if there are any libraries I would use that would be much appreciated.
I want to have a splash screen, something like a full picture, which doesn't crop in heigth or width on different smartphone screens.
Now I achieved a splash screen with android:scaleType="fitXY", but now the image is cropped on top or bottom or if the devices screen size changes to another aspect ratio it is cropped on the left and right.
What do I have to do? I've already read the android developer article Supporting Multiple Screens, but I don't get it how to achieve this.
A simple picture in the middle of the screen is just simple to get, but a picture which fills the screen is hard to get. Can you help me pls?
you should use center_crop per this purpose. From the doc
Scale the image uniformly (maintain the image's aspect ratio) so that
both dimensions (width and height) of the image will be equal to or
larger than the corresponding dimension of the view (minus padding).
There is no way to create one single asset and expect it to do not be cropper and to do not create black areas when the application is deployed in different screen sizes.
The android platform is designed to work dynamically with multiple screen sizes that any manufacture can change at any time, including new resolutions that you haven't thought about it yet.
Android can specify minimums for screen hight/width categories in which your resources will fall, but those are generics.
In order to use them, you will have to specify qualifiers in your drawables and create a different splash screen for every qualifier, as for example if you use drawable-w420dp, all the resources there will be used when the screen has a minimum width of 420dp (notice that are not pixels)
So you have two options:
You can use one single splash image and design margins of that image flexible enough in order to cope with the image being cropped in certain cases. You can play with different scaleTypes in your ImageView and take as a reference this website http://etcodehome.blogspot.co.uk/2011/05/android-imageview-scaletype-samples.html even though as commented before, "center-crop" will be your best shot.
You can programatically use a specific image for a specific resolution.
2.1 Put in the assets directory, all the splash images that you want for all the specific resolutions or aspect ratios that you want to use
2.1 Get the screen size of the device with Get screen dimensions in pixels
2.2 Now you can load from the assets the image that you want dynamically
Use the below code
android:layout_width="match_parent"
android:layout_height="match_parent"
which will fill the entire screen.
Try Using Width and Height of image to "match_parent"
I'm getting stuck at a certain part of my app.
In my app, I have a few icons. The icons are completely white with transparent backgrounds. Is it possible for the user to set the colour of the icons without messing up the transparency? I tried searching a lot, but couldn't come up with anything. Could someone help me out?
Also would it be possible for the user to set custom icons from any folder as per their choice?
Thanks.
Yes it's possible. You have to create bitmap from resource How to set a bitmap from resource, then search bitmap for white pixels and change them to desired color (pix - by pix), then just set result bitmap as button or other layout element bitmap.
I want to have an image on the android screen where different parts of the image can be clickable. What I mean is that, If its an image of 3 circles, I want to be able to click each of these circles,
Then I can add different functionalities to each of these clickable circles.
For an instance in this image below I want to be able to click each distinct color. Is it possible to have on-touch-listener and get you the color ? and can it be an image or has to be drawn in Java OR XML ?
I found a really good widget that helps you make any image muli-clickable. They have some good notes on how to use their widget as well.
The widget has a similar approach as Image mapping in html. The good thing about this widget is that the image can be zoomed and it will not lose the coordinates or areas associated to specific clicks.
Here is the link to their website. the guy who made the widget apparently had similar problem and came up with this widget.
Another solution would have been
creating an ImageView containing the png file referenced
making the whole ImageView clickable
setting an OnTouchListener to the ImageView which overrides the onTouch method
check the colors of the image pixel at the touch position
This is often done with an invisible mask image with one color for each zone (see the popular detailed tutorial), but here the image itself has distinct colors for each zone which makes it more interesting.