Set wrap_content in RecycleView holder:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#android:color/black">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:textColor="#android:color/white"
android:textSize="17dp"
android:background="#drawable/bubbleblue170x140_2" />
</RelativeLayout>
But text in TextView is not wrapped, there is a lot of empty space in the bubble, inside TextView.
How can I force to see something like this in iOS version:
In Android using 9-patch image as background.
The height of your text view is wrap and the big size is becuase of your 9patch image (probably having a big size)
And the width of that is match parent as you wanted in xml layput.
Just change the size of your 9 patch and make the width wrap content too
Resize your 9patch. You should also change the RelativeLayout's height and width to wrap_content. Or, even better, you should remove the RelativeLayout (it seems useless).
Related
Is it possible to forcefully set dimensions of a layout and clip its content?
For example, see following layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content>
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test" />
</FrameLayout>
In this layout, FrameLayout size will be equal to Button. Now assume that I want to set this layout's dimension to 50dp width and height, clipping all controls (here button) in that size, so that total size of layout will be 50dpx50dp. Is it possible to do so?
I thought setting width, height, and android:clipChildern="true" for layout should do the trick, but it seems that it does not work. or maybe I'm using it incorrectly.
I have an imageview that I want to fill it's parent RelativeLayout to act as a background image.
The image is the correct size until the other views in the relative layout expand, and thus expand the size of the entire layout (just height in my case) (ie: a large string from the internet has been loaded into a textView). Then the image view doesn't grow to continue matching the parent. Is that expected behavior and if so, how do we get around it?
Here's my layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/parentLayout">
<my.BlurredImageView
android:scaleType="centerCrop"
android:id="#+id/profile_bg"
ImageUrl= "Avatar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
<LOTS AND LOTS OF OTHER VIEWS>
OK I am sure you know this already, but for thoroughness I thought I should mention that the easiest way to set the background of the relative layout is directly in the background field:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="drawable file or file from internet you load programatically"
android:id="#+id/parentLayout">
Now to your question. If for whatever reason you really need an imageView as a background, then use the width and height as 0dp because you are aligning to parent on all 4 sides. See if this makes a difference:
<my.BlurredImageView
android:scaleType="centerCrop"
android:id="#+id/profile_bg"
ImageUrl= "Avatar"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
To check the actual size of the image view, and whether it fills your relative layout, the most practical way would be to make the background of the RelativeLayout bright green, and the background of the imageView bright Orange. Then you always know exactly where they are :-)
Essentially I'm looking for something like scaleType="centerCrop" without the center.
I am having trouble making an ImageView display correctly when it's larger than the screen dimensions. I'm trying to display an ImageView that starts top=0, left=0 and is not scaled. It's okay that the image does not fit on the screen. Right now I have it in a relative layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/postagram_blank_large"/>
</RelativeLayout>
I've tried using a wrap_content on the RelativeLayout height and width. I've also played with scaleType as well as using a Scrollview. The problem with the ScrollView is that the image is both taller and wider than the display port (again this is meant to happen).
How can I make this work?
could it be that android:background scales the image to the screensize? try to use android:src instead.
Try this:
<ImageView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="#drawable/postagram_blank_large"
android:scaleType="matrix"
/>
wrap_content instead of fill_parent also works, use whatever you want
In my Android project, I am not quite sure how to make my background image fill the entirety of the RelativeLayout root element in XML, which is the size of the screen. I want to be sure that this works for all aspect ratios, so the image will clip vertically or horizontally as necessary. Does someone know how to do this easily? I've only seen questions regarding ImageViews and Buttons, but not really generic Views.
My XML file currently:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/enclosing_rl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:fitsSystemWindows="false">
<!-- Other elements -->
</RelativeLayout>
Other than turning your image into a nine patch I don't think this is possible. What you could do instead is-
Add an ImageView as the first view in your RelativeLayout.
Set layout_centerInParent to true.
Have the layout_width and layout_height set to match_parent.
Then set scaleType to centerCrop.
That will make sure the image fills the screen without any distortion, but depending on screen size/orientation either some of the top/bottom or left/right of the image may be cut off.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
android:src="#drawable/background" />
Any other views in the RelativeLayout will appear on top of the ImageView, as long as it is the first view in the RelativeLayout (when you are in the xml).
Create a bitmap drawable XML resource in your res/drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background"
android:tileMode="repeat" />
Use that drawable as background instead of #drawable/background
according to this answer If you want your ImageView fill your RelativeLayout,use align parameters for ImageView.
you can put all of your views to a LinearLayout and set align parameter to your background ImageView:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/my_background"
android:scaleType="centerCrop"
android:layout_alignTop="#+id/my_views"
android:layout_alignBottom="#+id/my_views"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/my_views"
android:orientation="vertical" >
<!-- stuff -->
</LinearLayout>
</RelativeLayout>
Its smart and 100% working answer is to set the property scaleType of image view !
android:scaleType="fitCenter"
I'm trying to place an image that fills the width of the screen, has the height of the actual image (wrap_content) and sits at the very bottom of the Layout.
I've wrote the below code, but between the second ImageView (the one with drawable/user_board) and the very bottom of the screen, there is a small space. Why is this? I've tried setting padding and margins to 0dp, but it seems it doesn't do the trick. Any ideas?
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/LayoutBoard"
android:noHistory="true"
android:padding="0dp" >
<ImageView
android:src="#drawable/game_interface_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="matrix" />
<ImageView
android:src="#drawable/user_board"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0dp"
android:padding="0dp" />
</RelativeLayout>
Doesn't your user_board image have some transparent space at the bottom? Or maybe you can try setting negative value in the padding field of the second ImageView.
Use android:scaleType="fitXY" and the bitmap contained in your ImageView will be resized to fit the whole ImageView. So using this attribute in both your imageViews will probably hide that empty space. However keep in mind that this does not keep the aspect ratio of the image. See here for more information about the android:scaleType attribute tag and the possible values it can take.