I want to resize an ImageButton, but when i change the size of the ImageButton with the mouse on graphical layout on eclipse, and leave the left mouse button, the ImageButton returns to its original size. I have already tried this:
android:layout_width="50dip"
android:layout_height="50dip"
But it doesen't work for me.
The problem is that this button should be a hidden button, so i cut a part of background of my app to do this, but when i put this part on my app it is larger, so everyone can see the difference. The problem is that the app resize my background image to make it compatible with the screen.
The use of dip has been replaced by dp, which stands for Density Pixel.
Documentation on dp can be found here
Try using just 'dp' instead of 'dip'
"dp" is more consistent with "sp".
Related
I try to make an app but I have an issue with the background.
The above image shows what should look like the app. Every rectangle of color is a fragment and the red one already have the correct part of the background. But now I try to figure out how can i make the green rectangle background respect this rules :
Image width needs to match parent
The image needs to keep his ratio
Image need to "stick" the bottom (in that way the upper part shows in the red rectangle won't appears in the green one)
In the green fragment I have a ConstraintLayoutand an ImageView like above :
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ss_background_blur"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
The #drawable/ss_background_blur is my PNG image.
Thx
As Neo Shen pointed out in the comments, the only thing you need to do is set the background property of the container element to the drawable resource (the image).
If you have an Activity which only contains three Fragment elements, then you can set the background of the main Activity layout.
You can see and clone a quick demo I put together here:
https://github.com/sipox11/full-background-android-app
This is the result:
Note: I did it very quickly so obviously the tabs are not real tabs and the top bar is not a real nav bar, but you get the idea.
In this case the background image is actually below the tabs area, but if you want it to start on top of it, you can wrap the top and middle fragments within a LinearLayout and set the background image to that container.
Hope it helps,
Cheers.
Set the background of the rootlayout to green and add android:layout_margin="2dp" to the imageview .
Hope this helps.
Goal: A highlighted section of an image (the image covers the whole screen). The rest of the screen needs to be faded out.
Example
So far I've got the fading working using the foreground of a FrameLayout and placing the image as the background of a RelativeLayout within the FrameLayout. The solution I'm thinking is that I need to create 2 Drawables and merge them into one that FrameLayout Foreground can consume.
I've also been reading a bit up on PorterDuff, but I think that may be overkill for what I'm trying to achieve.
The fade functionality is working fine, but the source of the fade with transparent section is not.
I suggest that you have the original image in an ImageView on top of it place 4 views which are partially dimmed and that's it!
With some basic math you can know the sizes for each view, and using RelativeLayout will allow you to easily place them on the screen.
Good Luck!
P.S. I've attached a sketch to illustrate what I'm suggesting.
I'd like to create a textview that contains a blue line as it's background just like in the image I provided. You can also find it in Google calendar when entering appointment info.
I previously tried using 9patch images to stretch the line horizontally and keep the vertical scaling the same. But that does not work. I'd like to also use this in other view to provide my own background to other views. Any hints?
Thanks you in advance!
I believe that you are looking for the EditText layout item, not TextView. It will automatically change the line to the blue color when the user places the cursor there, otherwise it will be black.
you can use a relativelayout for your edittext, and for the lines, a view 1dp high at it's bottom (width matchparent so it stretches) , and two 1dp wide views at its sides, that'd accomplish that effect (as high as you want them).
I have a background image of size 720x1280 for larger screen phones like the LG Nitro P930. However, when I have an application that displays this image, it doesn't cover about half an inch at the bottom of the screen. The image looks fine on normal and small screen sizes, and I have included all of the support screens in my manifest file.
Is there something that I can do that will allow me to stretch the image to fit the screen, or am I doing something wrong?
add android:scaleType="fitXY" and fill_parent for height and width both in you layout xml
You don't have to use image view background should work fine, are you using a scroll view per chance somewhere?
I figured it out. It was actually a setting on the phone that optimizes the application.
so I have this problem with ImageButton class of libgdx, the problem is that in android the image doesnt expand to the full size of the button, and in desktop it does or at least it does more, so I have to ask if theres a way to force the image to get the size of the background(button)? so i can try to make an equal visualitation on both plataforms.
heres a screen shot, the back space button is the ImageButton...
edit: heres the code....
private void createButtons() {
ImageButtonStyle ibs = new ImageButtonStyle(buttonD,buttonD_p,buttonD,bsIcon,bsIcon,bsIcon);
buttonBS = new ImageButton(ibs); // This is the backspace button
....
}
private void addButtonsToTable() {
float pad = 1;
float BUTTON_SIZE = this.BUTTON_SIZE - pad *3;
table.top();
table.center();
table.add(buttonBS).width(BUTTON_SIZE).height(BUTTON_SIZE).pad(pad);
table.row();
...
}
If you want the image to be the background instead of just an icon, you should consider using plain Button or TextButton instead of ImageButton. ImageButton should be used only for buttons that draw an icon additionally to its background. An example of ImageButton usage could be the window closing button with the "X" (cross) image, or music toggle button with a loudspeaker icon.
When you need the image to fill the whole button area, set it as ButtonStyle#up - it will become button's background. ImageButton#imageUp is just an icon that will not be scaled in any way (by default), so that might be the reason why your application behaves differently on each platform.
(Although it still shouldn't, unless you use different assets.)
If you need an icon and still want to use ImageButton, consider that internally it is just a Button with an Image instance added to one of its cells (Button is a Table). You can use ImageButton#getImageCell() to access Cell in which the Image is stored and modify it - for example, force a specific width and height. You might also want to use ImageButton#getImage() to change scaling with Image#setScaling(Scaling).
Anyway, creating styles at runtime can be error-prone - the style constructor is huge and I'm honestly unable to guess which drawable draws what without checking out image button style sources. You should consider using Skin and define your styles with JSON files (you can find some free themes here).