I have a LayoutView in a ScrollView and want to set a my glass background PNG image that should be scaled automatically to wrap content.
In these layout view, there is a text view and the contents of this text area is variable.
Usually without any PNG background the size of layout view is not extended if isn't necessary to view all the text set, but when I set PNG background the layout view automatically enlarged to the size of the PNG if I set wrap content on layout view.
How to set a custom background image scalable to fit the size of layout view that doesn't influence the wrap content behavior?
As per your requirement i would suggest you- take your background image of Height= approx 50 pixel width= any
- convert this image into nine patch follow this link- http://developer.android.com/reference/android/graphics/NinePatch.html
by using nine patch images your background will be re sized/adjust as per the dynamic data.
Hope it helps.
Thanks
In my opinion, you have to:
Set scaleType of Image view = "fitXY"
Set layout_height, layout_width of layout = "wrap_content"
Related
I have a background image, which is simply colored panel such as silver purple, etc.,
This background image is set as andorid:background of RelativeLayout, which consist of a ImageView
I want that imageview's image resource to be appear like in center of the background image.
I tried alignParentTop and marginTop to position the combo image in center.
It works as expected, but when trying on different devices, as marginTop is hardcoded such as 10dp,, or 5dp, the alignment looks differently on different devices with different resolution.
I have even created various dimens.xml files for various configuration with various marginTop dp values. Still it only works on specific devices and doing fro all devices is obviously impossible. So i need to set or align the background and foreground images such that foreground image is centered over background image.
Note: Using Framelayout is not of my concern. I want this by RelativeLayout.
On the ImageView and the parent RelativeLayout, remove all of the padding and margin stuff you have, then add android:layout_centerInParent="true" to the ImageView. If you know the height and width of the image in the ImageViewbeforehand, set the ImageView to match it identically (in dp's). Otherwise, try setting the ImageView height and width to wrap_content and potentially android:adjustViewBounds="true".
I have given the image view of certain size the image which i have smaller size than the image view when i fit the image view it is looking like the picture is at the corner but i would like to get the picture in certain pattern such as after filling the smaller image in the image view on the corner the remaining space of the image view should be filled with the same smaller pic until it fits the size of the image view.
Use android:scaleType="fitXY" and android:adjustViewBounds="true". This will work in your case.
Try this, Add scaleType attribute in your xml file
android:scaleType="fitXY"
In your layout file where the ImageView component is you can add this attribute
android:scaleType="fitXY"
I have Imageview which i am creating it dynamically,now i am setting
imageView.setImageBitmap(bitmap);
imageView.setBackgroundResource(R.drawable.a);
What is happening is the setBackgroundResource image is stretching,as the bitmap size increases.
Why is it so?Is there any workaround?
A Background resource is designed to fill up the entire View, which is why it stretched when the contents of the View are increased in size.
A possible workaround would be to use a 9-patch drawable, which only stretches are specified by you.
Another workaround would be to scale your background as your normal View Contents increase, and reset it to the new background.
I have a ExpandableListView and i am setting the background image when the group is expanded,
but issue occur that when i set the background image size is changed to current background of group,
any help ??
see below image
I think there is different in your Image size, so its changing height according your Image size as you would take WRAP_CONTENT in Height.
Do fix your height or make sure that both Image are with same height and width.
I'm trying to make a LinearLayout that has height = LayoutParams.WRAP_CONTENT.
I am receiving an arbitrarily sized bitmap from a server to set as the background image for the LinearLayout.
How do I set the background image of the LinearLayout without resizing the view if the received bitmap is larger than the contents of the linear layout?
It would be nice if the background image could maintain its aspect ratio, and scale to match the width of the screen.
I tried overriding onMeasure as a temporary solution, but that just wound up biting me.
how about using an imageView inside your layout , which also has its adjustViewBounds set to true in order to keep aspect ratio?