I have the following layout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:text="text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="5dip"
android:textColor="#ededed"
android:fadeScrollbars="true" />
</RelativeLayout>
In the code I use the following to set the maxWidth size which is customizable by the user:
textview.setMaxWidth(768);
The issue I'm facing is, the maxWidth setting only works up to what seems like 620px. Anything above that has no effect. If I set the textview width to 768px it stil has no effect but if I set the relative layout width to 768px then the textview maxWidth works above 620px.
So it seems the issue is the relative layout isn't wrapping as expected and is limiting the width. I don't want to have to set a static width on the relative layout as this would defeat the purpose (for my application) of using a maxWidth inside it. And this issue isn't device specific either, it seems to cap at that point on any device.
Does anyone have any ideas why this is happening or how I can work around it without specifying a static with for the relative layout?
Is the core issue that you would like the contents of your textView to wrap? If so, you might want to look here: How to line wrap Android TextView views?
Related
I'm creating an app that uses an ImageView in the main activity that covers the whole width of the screen, the height should fit the image's resolution.
Here's my xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:adjustViewBounds="true"
android:id="#+id/bgImage"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/bg_home_blue"/>
</RelativeLayout>
Here's what my layout looks like:
Everything seems to work fine but I don't know where these paddings are coming from, I've tried to change the scaleType but nothing seems to work.
Edit:
If I put instead of src just a blue background, the paddings go away and it fills the whole width (than I need to set a specific height as well)
I guess your image is png and have that space around it, even when your scaleType is FitXY it doesn't mean that it will remove the space around the png file, check that out and let us know what happened, or at least upload your image file
I have a bitmap which I am reading from a particular location on the device like such and am setting the image to an ImageView
scaledBitmap = BitmapFactory.decodeFile(selectedImagePath);
ivImage.setImageBitmap(scaledBitmap);
And thats how I am setting the xml code for that imageview
<ImageView
android:id="#+id/ivImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:scaleType="fitXY" />
Is there a way I can remove the blank space above the image inside the ImageView?
Try Change android:scaleType="fitXY" to android:scaleType="centerCrop"
I had the same problem, and what I remember is removing adjustViewBounds attribute line from code will fix it. Try this and let me know.
scaleType="fitCenter" (default when omitted)
will make it as wide as the parent allows and up/down-scale as needed keeping aspect ratio.
scaleType="centerInside"
if the intrinsic width of src is smaller than parent widthwill center the image horizontally
if the intrinsic width of src is larger than parent widthwill make it as wide as the parent allows and down-scale keeping aspect ratio.
It doesn't matter if you use android:src or ImageView.setImage* methods and the key is probably the adjustViewBounds.
use this
<ImageView
android:id="#+id/ivImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:scaleType="centerCrop" />
I've been trying to increase the size of a ImageButton/ImageView in a relative layout with all the possible attributes but had no success. no matter what size I put. As I checked the displayed button is 32dp, if I lower the value the image will resize to small but will never enlarge more than 32dp.
I am kinda confused here, 32px is xhdpi image size, is that the reason its not enlarging ?
Image is the made accordingly to support all the 5 dpi (mdpi, hdpi, etc ..)
this activity belong to layout-large as I am trying to make it for large screen as well.
here is how I am doing it:
<ImageView
android:id="#+id/quantity_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/product_qty"
android:background="#android:color/transparent"
android:src="#drawable/ic_button_add"
android:adjustViewBounds="true"
android:maxWidth="100dp"
android:scaleType="fitXY"
android:layout_centerVertical="true" />
</RelativeLayout>
You want to increase the size then do this:
<ImageView
android:id="#+id/quantity_plus"
android:layout_width="100dp"
android:layout_height="60dp"
android:layout_toRightOf="#id/product_qty"
android:background="#android:color/transparent"
android:src="#drawable/ic_button_add"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_centerVertical="true"/>
Instead of Wrap_Content for width & height specify some size
change the width & height according to your required need
Edit:
wrap_content will always just wrap your image & will not increase the size of the imageview
To use on different size devices:
put the values in res->values->dimens folder for normal, small & large devices
and use like :
android:layout_width="#dimens/widthSize"
android:layout_width="#dimens/heightSize"
Well you are using wrap content for your width and height. With those set it will always just wrap the image and not be any large.... Even if your MaxWidth is set to a larger size. You will need to set those values to a specific value either in your XML or in your class in Java. Hope this helps!
You can change height and width accordingly using layout_width,layout_height tag.scaleType="fitXY" can be distorting the image so use scaleType="fitCenter" maybe that can help.
<ImageView
android:id="#+id/quantity_plus"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_toRightOf="#id/product_qty"
android:background="#android:color/transparent"
android:src="#drawable/ic_button_add"
android:adjustViewBounds="true"
android:maxWidth="100dp"
android:scaleType="fitXY"
android:layout_centerVertical="true" />
So, I'm trying to view a camera preview as a background with an imageview on top of it. Check this question out, that I've asked, to get a better idea of what I'm trying to accomplish. However, instead of using a FrameLayout, I found it easier to use a RelativeLayout (for the reason of placing views where I want on the screen). The problem is that I can't get the imageview (over the surface view) to take up the whole screen. No matter how I re-size the image it still displays in the center without filling the screen.
So, my question is, how would I make the imageview fill the entire screen over the surface view? Perhaps, I am making a simple mistake but if that is the case please point it out. Any help will be greatly appreciated! Thanks!
Here's the XML file:
<?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/relative" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/image"
android:src="#drawable/background" >
</ImageView>
<Button
android:id="#+id/scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:text="Scan"
android:textSize="20dp"
android:textStyle="bold"
android:onClick="Scan" />
<Button
android:id="#+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/scan"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="Search"
android:textSize="20dp"
android:textStyle="bold"
android:onClick="Search" />
<Button
android:id="#+id/importing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/search"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="Import"
android:textSize="20dp"
android:textStyle="bold"
android:onClick="Import" />
</RelativeLayout>
And here's the code where I place the views (bring to front so they are visible over the surface view):
mPreview = new CameraPreview(this, mCamera);
relative.addView(mPreview);
layout.bringToFront();
scan.bringToFront();
search.bringToFront();
friendImport.bringToFront();
EDIT:
Here's an example image of what I'm talking about (I am trying to get the white transparent image to cover the whole screen):
Am I correct that you want to stretch android:id="#+id/image" into your entire layout?
First check in layout view that the ImageView takes entire space as it is supposed to.
If so, then add the proper scaling type to your ImageView attribute list:
android:scaleType="fitXY"
Or as an alternative, apply the image resource not as "src" but as "background":
android:background="#drawable/background"
Good luck.
After experimenting for a while, I seem to have found a solution to my problem. My image was showing up similar to this picture:
Which is weird, because this is how a 9-patch image works and I did not declare my image as a 9-patch. But even when I called match_parent (or even fill_parent) it only filled to the fill area like in the image I posted.
So, with lots of trial and error, I took away any border that was on the image and took all the blur effects off. The image was, for some reason, a dramatically smaller file size. Then, I tried to place this as the background and... success!
I'm not too sure as to why it did not work to begin with, but, I have a theory that, perhaps, because there was a 1px border on the image it saved it as a 9-patch PNG instead of a normal PNG file. Or maybe it was due to the blur effect that was on the image. I'm not too sure, but, I do know that once I took off the blur effects and removed the border it did work.
I hope this is useful for anyone who might be faced with a similar problem!
Can you help me to configure my layout? I don't achieve what I'm looking for:
I've put the imageview background to red for explain what I want:
The image's width is smaller than the layout width. I'd like the image grow proportionally keeping its aspect ratio until reach the aspect at the first image (I modified it manually with photoshop) but when setting width="fill_parent" the result is the second image and setting both width and height to "fill_parent" the result is the third image.
I tried to combine with ScaleType with no success
How can I achieve the first option? Thanks
Use android:adjustViewBounds=true attr in xml for ImageView
This question is solved here by extending the ImageView class.
Android ImageView adjusting parent's height and fitting width
I created a sample. It works for me. Here is the xml layout file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="#drawable/hydrangeas"
android:layout_height="wrap_content" android:id="#+id/imageView1"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:background="#android:color/white"
android:layout_width="wrap_content"/>
</LinearLayout>
It works for fitCenter too. Have a look at the snapshot.
Use the attribute fit_center into your ImageView tag.
<ImageView ... android:scaleType="fitCenter" .. />