I am using Universal Image Loader to grab some images and display them in a listview. I am having trouble getting the layout looking right. I want the image to use no more than 25% of the width, and this looks fine in the Graphical Layout view in Eclipse, but when the image is downloaded it is displayed full size which is too large.
I was hoping to avoid using maxwidth as I dont know what the full width will be.
This is my layout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="100" >
<ImageView
android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_weight="25"
android:contentDescription="#string/offerImage"
android:paddingRight="10dip"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="75"
android:orientation="vertical" >
<TextView
android:id="#+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="tempString"
android:textColor="#ffffffff"
android:textSize="18sp" />
<TextView
android:id="#+id/txtRetailer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Business name"
android:textColor="#ffffffff"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="99.99 miles"
android:textColor="#ffffffff"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
I had some trouble with the sizes of ImageViews that are used with UIL too and this helped me:
iv.setAdjustViewBounds(true);
Might be worth a try.
The solution is to set layout_width value to 0dip for both ImageView and LinearLayout.
layout_weight works only for unused space, so in case image is too large there is no any free space.
In your xml file add this in your imageView Tag
Add this
android:scaleType="fitXY"
Related
So I have a image view and below a relative layout. The desired is to always have the users see the text views and buttons in the nested layout. And the image is a top image ( not a full screen background) but some how there is a small gap and the background of the image is bleed past the image view. I have tried different Image scale types and different layouts completely(frame, all linear,etc..)
http://imgur.com/a/n4aIq
and some code
https://gist.github.com/whatkai/92f66d2322957d86dd3fe28a9a5d03c0
FYI layout-weights left gaps too.
There is too many ways to do it.
Try this solution using LinearLayout (orientation: vertical):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/REFragment"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/accidentAssistanceColor">
<ImageView
android:id="#+id/SettingsImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#string/app_name"
android:scaleType="fitXY"
android:src="#drawable/ers"
android:layout_weight="1"/>
<LinearLayout
android:background="#color/appStartERSBackground"
android:layout_centerHorizontal="true"
android:id="#+id/onView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/SettingsImage"
android:gravity="bottom|clip_vertical|center"
android:orientation="vertical">
<Button
android:gravity="bottom|end"
android:layout_centerHorizontal="true"
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/transparent"
android:text="Not Now"
android:textColor="#color/white"/>
<Button
android:id="#+id/button2"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/button"
android:text="approve"
android:textColor="#color/white"/>
<TextView
android:gravity="center_horizontal|center_vertical"
android:id="#+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/button2"
android:layout_gravity="center"
android:text="BLdfdsAH"
android:textColor="#color/white"/>
<TextView
android:gravity="center_horizontal|center_vertical"
android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BLAH"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
And to answer you about how to scall your image i used android:scaleType fitXY to respect to ratio aspet.
If you desire to understand how every scallType works, see the following link:
https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide
set view tag between your image and layout.
like this.
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000000" />
I use a relative layout to display a row in a listlayout. What I am showing is an imageview to the left and two textviews to the right. Both the textviews will only have a single line each.
I need to have the image such that it should be automatically resize so its height becomes equal to the height of the text combined. That way, the image height will fit the combined height of both text in all screens. Is this possible? layout is as below -
<ImageView
android:id="#+id/note_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:src="#drawable/note_icon" />
<TextView android:id="#+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/note_img"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:includeFontPadding="true"
android:singleLine="true"
style="#android:style/TextAppearance.Medium" />
<TextView android:id="#+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/note_img"
android:layout_alignParentBottom="true"
android:layout_below="#id/text1"
android:singleLine="true"
style="#android:style/TextAppearance.Small" />
As of now,note_img has a size of 96x96 and the image is shown in full size making the image area considerably large and the two text having huge gap between them.
Really appreciate any help.
Thanks,
Arun
Don't use fill_parent, it's depreceated. Untested, let me know if it works:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/note_img"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="6dip"
android:src="#drawable/note_icon" />
<LinearLayout
android:id="#+id/vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/text1"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="true"
android:singleLine="true" />
<TextView
android:id="#+id/text2"
style="#android:style/TextAppearance.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout>
After set the Text in TextView set the TextView's height to ImageView like
imageview.getLayoutParams().height = textViewheight;
I have an imageview and textview in a LinearLayout with horizontal orientation. Do not know why the textview has a space on the left that I can not remove ...
I tested with padding, gravities, etc. ...
This is my xml and result in an image
Any idea?
Thank you!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left|center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dot" />
<TextView
android:id="#+id/text_resultado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:padding="3dp"
android:text="TextView"
android:textColor="#color/negroLetras"
android:textSize="#dimen/titles" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:paddingBottom="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:text="%"
android:textColor="#color/negroLetras"
android:textSize="#dimen/titles" />
</LinearLayout>
Propably you have something wrong with you drawable "dot" or other values like dimen etc.
I think that because I used your code without this values with other sample values and layout was ok.
There is no problem in your code. Your code is perfect. May your problem be in image. Check it or replace it with other and then check it.
May i suggest you to change a little bit your layout?
Delete second LinearLayout and use a TextView like this:
<TextView
android:id="#+id/text_resultado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/dot"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:padding="3dp"
android:text="TextView"
android:textColor="#color/negroLetras"
android:textSize="#dimen/titles" />
I know this question has been asked multiple times, but I have looked on all the solution I could see and none of them worked.
I have a textview inside a relative-layout. the textview has a height : fill_parent atribute that does not work. the pun is that they are severall other textview in this relative-layoutwhich all manage to fill parent,except for this one.
here is the XML :
<?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="wrap_content"
android:background="#drawable/customshape"
android:orientation="horizontal" >
<TextView
android:id="#+id/mainlistdescription"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scrollHorizontally="true"
android:maxLines="4"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/mainlistquantite"
android:layout_gravity="center_vertical"
android:textSize="12sp"
android:padding="10dp"
/>
<TextView
android:id="#+id/mainlistquantite"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:maxLines="4"
android:layout_toLeftOf="#+id/consultaffichelayoutdroit"
android:textSize="12sp"
android:padding="10dp"
/>
<TextView
android:id="#+id/consultafficheseparator" <!-- the one not working-->
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/imageView1"
android:background="#777777"
android:maxWidth="2dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical|right"
android:src="#drawable/fleche" />
<LinearLayout
android:id="#+id/consultaffichelayoutdroit"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/consultafficheseparator"
android:orientation="vertical"
android:paddingLeft="5dp"
>
<TextView
android:id="#+id/mainlistnumero"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/mainlistprix"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
here is what i get :
the grey bar should go all the way but doesn't when actually running on the emulator( it does in the eclipse tool)
since this xml is actually called in a list view, I can't seem to fix the problem using JAVA code, so the solution would ideally be on the XML file. I tryed so far android:clipChildren="false" without sucess, as well as changing the order of my elements in the XML, wich juste made it worse.
after experiment,I can tell nothing takes the place so it's not the it cannot go because there is allready a view there,it just doesn't expand that far
thanks for the help on that
Why are you using a TextView to draw a separator? Try with a normal view like the code below.
Also, if the seperator has to align to the bottom of your description view, you can use the layout_alignBottom-property of RelativeLayout like this:
android:layout_alignBottom="#+id/mainlistdescription"
So the separator would look something like the code below:
<View
android:id="#+id/consultafficheseparator"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/imageView1"
android:layout_alignBottom="#+id/mainlistdescription"
android:background="#color/separator_bg" />
Below some other tips:
It's better to define a color in some resource-file (eg. colors.xml) and refer to that color from inside your layout. Especially when using it in a ListView
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="separator_bg">#777777</color>
</resources>
And in your layout-file android:background="#color/separator_bg"
Use match_parent instead of fill_parent because that's deprecated.
I see android:scrollHorizontally="true" on one of the TextView's. That only works when the TextView is editable. If you want the content to scroll because it doesn't fit in the TextView, try to use the code below:
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
And in your adapter.getView():
final TextView description = (TextView) view.findViewById(R.id.mainlistdescription);
description.setSelected(true);
It looks like your TextView is not at the top level, maybe you can try the following in your code:
consultafficheseparatorTextView.bringToFront();
Had the same pesky problem which by the way makes no sense. What worked for me in the end was changing the android:layout_height in RelativeLayout tag to fill_parent like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/customshape"
android:orientation="horizontal">
hope this helps
Try setting one (or all) of the following to see if it changes anything:
android:maxHeight="100dp"
or
android:layout_height="100dp"
or
android:text="a"
android:textColor="#777777"
If any of these options change the size, please let me know and we can work on a proper solution!
It's very strange you get such view of this layout, because after copy&paste of your layout code I've got this one.
Your solution works, I've made some minor improvments. It's like your code, but there is no need to use TextView if you need background color only, View could be used instead.
<View
android:id="#+id/consultafficheseparator"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/imageView1"
android:background="#777777"
/>
Only suggestion is to set root layout height "match_parent" or some value in dp, like thiagolr proposed. I've set it to "100dp" for this screenshot.
This is what you should do,
<?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="wrap_content"
android:background="#drawable/customshape"
android:orientation="horizontal" >
<TextView
android:id="#+id/mainlistdescription"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scrollHorizontally="true"
android:maxLines="4"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/mainlistquantite"
android:layout_gravity="center_vertical"
android:textSize="12sp"
android:padding="10dp"
/>
<TextView
android:id="#+id/mainlistquantite"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:maxLines="4"
android:layout_toLeftOf="#+id/consultaffichelayoutdroit"
android:textSize="12sp"
android:padding="10dp"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical|right"
android:src="#drawable/fleche" />
<TextView
android:id="#+id/consultafficheseparator" <!-- this will work now -->
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/imageView1"
android:background="#777777"
android:maxWidth="2dp" />
<LinearLayout
android:id="#+id/consultaffichelayoutdroit"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toLeftOf="#+id/consultafficheseparator"
android:orientation="vertical"
android:paddingLeft="5dp"
>
<TextView
android:id="#+id/mainlistnumero"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/mainlistprix"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
1)Try to make your Linear Layout orientation vertical
or
2)Try to make your Relative Layout orientation vertical
it can be help.
This is my layout for an image capture program in android
<?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">
<SurfaceView android:id="#+id/surface_camera"
android:layout_width="fill_parent" android:layout_height="420px">
</SurfaceView>
<RelativeLayout android:layout_width="fill_parent"
android:layout_alignParentBottom="true" android:id="#+id/beforeClick"
android:layout_height="wrap_content" android:background="#color/clickPanelBK"
android:paddingTop="6dp" android:paddingBottom="6dp">
<Button android:gravity="center" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/capture_image_goback_btn"
android:background="#drawable/generalbutton" android:text="#string/back" />
<Button android:gravity="center"
android:layout_centerHorizontal="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/capture_image_btn"
android:background="#drawable/clickbutton" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_alignParentBottom="true" android:id="#+id/afterClick"
android:layout_height="wrap_content" android:background="#color/clickPanelBK"
android:paddingTop="6dp" android:paddingBottom="6dp">
<Button android:gravity="center" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/img_retake"
android:background="#drawable/generalbutton" android:text="#string/retake" />
<Button android:gravity="center"
android:layout_alignParentRight="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/img_save"
android:text="#string/saveImg" android:background="#drawable/generalbutton" />
</RelativeLayout>
</RelativeLayout>
The last 2 relative layouts are swappable and are aligned fine. Only one of them appear at a time and is changed on a button click. Anyway, The problem here is, I have to mention the layout_height of surface view in px or dp. If I give layout_height as fill_parent, the view appears very small, 35% of width and height. Can anyone please give me a solution ?
RelativeLayout had many bugs in 1.5 :(