In my Image Buttons, there is a lot of white space around the source image. Is it possible to remove this space so that the imagebutton just surrounds the source image itself.
<ImageButton
android:id="#+id/story_1"
android:src="#drawable/my_story"
style="?android:attr/borderlessButtonStyle"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:contentDescription="Add my story" />
Try this
<ImageButton
android:id="#+id/story_1"
android:src="#drawable/my_story"
style="?android:attr/borderlessButtonStyle"
android:background="#null"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:contentDescription="Add my story" />
Probably the problem caused by the image transparency. Try remove the white spaces around the image and make those areas transparent.
make sure the original image you are using doesn't have too much white since you already have the solution in your xml scaleType="fitXY" you can try scaleType="fitCenter" but your image is already stretched to fit your entire button in the orginal code
Related
my problem seems to be easy but I have no idea how to solve it.
I have a few buttons and all of them have a background image. The problem is, all images turns into blue color
It looks like this:
Original photo:
Here's a part of my xml code:
<Button
android:id="#+id/memory_button1"
android:layout_weight="1"
android:maxWidth="30dp"
android:maxHeight="30dp"
android:onClick="#{()->viewModel.showTile(1)}"
android:background="#{viewModel.button001}">
</Button>
Icons url:
https://www.flaticon.com/packs/restaurant-225
Better approach to use ImageView as button with ripple click effect would be
<ImageView
android:id="#+id/memory_button1"
android:layout_weight="1"
android:maxWidth="30dp"
android:maxHeight="30dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:onClick="#{()->viewModel.showTile(1)}"
android:src="#{viewModel.button001}"/>
Also you can even wrap it in a CardView
If you want to have the only image in your button. you can replace it with ImageView so that you can have full control of how the image is being drawn.
<ImageView
android:id="#+id/memory_button1"
android:layout_weight="1"
android:maxWidth="30dp"
android:maxHeight="30dp"
android:onClick="#{()->viewModel.showTile(1)}"
android:src="#{viewModel.button001}">
</ImageView>
You will option for scale type for ImageView's so that you can render image without stretching it.
I have an ImageButton that is the child to a RelativeLayout that uses a mipmap resource for it's source. However I'm having an issue with the mipmap stretching to fill the ImageButton.
In all of the threads I've read people have recommended "android:scaleType="fitXY"" yet this does not seem to work for me. The XML is listed below.
<RelativeLayout
android:layout_width="330dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp">
<EditText
android:id="#+id/search_edit_text"
android:layout_width="280dp"
android:layout_height="50dp"
android:hint="#string/search_hint"
android:background="#EAEAEA"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_margin="0dp"
android:textColorHint="#C9C9C9"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toRightOf="#id/search_edit_text"
android:layout_margin="0dp"
android:scaleType="fitXY"
android:padding="0dp"
android:stateListAnimator="#null"
android:src="#mipmap/search_button_icon"
android:background="#null"/>
</RelativeLayout>
The image below is the result of the above XML, however the search button (to the right of the edittext element) should be the same height, and be attached to the edittext.
Any help is appreciated.
I just copy/pasted your code, and the image below is what I get (I used default android:src="#mipmap/ic_launcher")
And I get a visual similar to yours.
Where it looks like the image isn't "stretching"
However if you click on the image you see that image's boarder perfect matches the EditText to its Left.
So my guess is that your input Image 'search_button_icon' Has built in padding in the Image itself and would need to be cropped if you want it to be 'exact' visually as the EditText.
Sorry for the my English, Actually the problem is that i get the images through json in android but when i show it in full size the image got stretched can you please tell me what to do??
this is my xml file
<ImageView
android:id="#+id/portFullImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="115dp"
android:layout_marginLeft="18dp"
android:layout_marginRight="22dp"
android:layout_marginTop="70dp"
android:src="#drawable/logo" />
maybe you can try with scaleType in your ImageView
<ImageView
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
You have specified top and bottom margins by using android:layout_marginTop="70dp" and android:layout_marginBottom="115dp" which are very big amount of space if device is small in my opinion. it will make your ImageView already small.
If you don't bother about it, try android:scaleType="centerInside" and see if it helps. You may try other scaletypes mentioned in below reference document and check the results.
Reference:
Various ScaleType of ImageView , ScaleType
How can I prevent the ImageButton from stretching the image?
Using this snippet:
<ImageButton
android:src="#drawable/prediction"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_horizontal"
android:scaleType="centerInside"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:contentDescription="some description"
android:text="#string/predict"
local:MvxBind="Click ExecuteQueryCmd" />
I get the following effect:
Image is 64x64 png.
All I want is for the ImageButton to respect native width and length, hence resolution, of the image it is being assigned. Recommendations based on a similar post is to use a Button, set its background to an image then use custom selectors but this sounds like a hack. Or is this the proper way to do this?
It work for me with
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="#android:color/transparent"
android:contentDescription="some description"
android:scaleType="centerInside"
android:src="#drawable/ci_icon"
android:text="#string/predict"
local:MvxBind="Click ExecuteQueryCmd" />
Put your image in android:src attribute
Set the width of the ImageButtons to fill_parent and use scaletype fitStart for the images that hug the left margin, and fitEnd for the ones on the right. Should do the trick, at least as far as your example image goes. You may have some spacing issues if the proportional width of the images exceed the screen width, but it should work for you.
Do this:
<ImageButton
android:src="#drawable/prediction"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:contentDescription="some description"
android:text="#string/predict"
local:MvxBind="Click ExecuteQueryCmd" />
My designer keeps adding a little padding around my image.
I want the image the stick on the top and to fill out the width of the screen.
Here's a screenshot from the designer:
This is my XML code:
<ImageView
android:id="#+id/markertap_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/header_bootsverleih_xhdpi" />
It looks like the image is larger than the screen width, so it's getting scaled down after sizing. Try adding android:adjustViewBounds="true" to your ImageView.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:id="#+id/imageView"
android:cropToPadding="false"
android:scaleType="fitXY" />
Experienced the same when I used an ImageView for Splashscreen, this^ worked for me.
you might want to add it your image view only this.
It fixed my problem.
android:paddingVertical="0dp"
android:paddingHorizontal="0dp"