ImageView getting very small under a linear layout - android

In one of my screens, I expect to acheive this kind of a layout
Highest importance being the images correctly scaled. These images i am giving are of adequate resolution and works fine on another fragment layout.
My layout.xml looks like this
<?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:background="#drawable/stadiumbg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/listview_item"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:orientation="vertical" >
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:adjustViewBounds="true"
android:padding="5dp"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="70%"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="80%"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<ImageView
android:id="#+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:adjustViewBounds="true"
android:padding="5dp"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/listview_item"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vote" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Down Vote" />
</LinearLayout>
</LinearLayout>
Everything else is great. The drawable listview_item is something that has been given to provided rounded corners, and tested in a listview with the above said images. Perfectly fine.
But in this layout, both the images gets super downscaled. It is like this.
wasting all that space for no reason.
What I have tried:
adjustViewBounds set to false
Scaletype as fitXY
Any idea to get What I want?

Change the width and height of the ImageView. Instead of:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Use:
android:layout_width="200dp"
android:layout_height="200dp"
Change the numbers to fit what you want.

Related

Put text and image on the same line

I'm trying to put text and an image on the same line but for one reason or another it's not working. The text is coming up fine but there is no sign of the image.
<LinearLayout
android:id="#+id/list_item3"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_below="#+id/list_item"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:background="#DCDBDB" >
<TextView
android:id="#+id/TextView03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:text="#string/quoteDevil"
android:textSize="21sp" />
<ImageView
android:layout_width="33dp"
android:layout_height="match_parent"
android:layout_marginRight="15dp"
android:src="#drawable/nextarrow" />
</LinearLayout>
FYI: There is a "tip" for displaying an image within a TextView.
In fact, any images stored in the drawable folders can actually be embedded within a TextView at several key locations in relation to the text using the android:drawableRight / android:drawableLeft and the android:drawablePadding property.
An example:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/my_contacts"
android:drawableRight="#drawable/ic_action_add_group"
android:drawablePadding="8dp"
/>
The result is:
Source: Link
The best way to have two things in one row is to use TableRow
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_item3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/list_item"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TextView03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/quoteDevil"
android:textSize="21sp" />
<ImageView
android:layout_width="33dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginRight="15dp"
android:src="#drawable/nextarrow" />
</TableRow>
</LinearLayout>
but if you want to use LinearLayout you have to define orientation as horizontal
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_item3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/list_item"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true">
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/quoteDevil"
android:textSize="21sp" />
<ImageView
android:layout_width="33dp"
android:layout_height="match_parent"
android:layout_marginRight="15dp"
android:src="#drawable/nextarrow" />
</LinearLayout>
U need to add orientation property to LinearLayout:
android:orientation="horizontal"
and change the width property from the inside elements from match_parent to wrap_content, if you put match_parent only show one element
Change
android:layout_width="match_parent"
For
android:layout_width="wrap_content"
Example
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_item3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
In RelativeLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView2"
android:layout_width="80dp"
android:layout_height="80dp"
app:srcCompat="#drawable/centra_crm" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/imageView2"
android:padding="5dp"
android:singleLine="true"
android:text="Title" />
</RelativeLayout>

Alignment of an Android layout

I have this layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<RelativeLayout
android:id="#+id/visual_compass_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="0dp"
android:padding="0dp" >
<ImageView
android:id="#+id/visual_compass"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:contentDescription="#string/visual_compass"
android:scaleType="fitCenter"
android:src="#drawable/compass_1000x1000_white" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/visual_compass_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/visual_compass_value_default"
android:textColor="#ddd"
android:textSize="#dimen/visual_compass_value_text_size" />
<TextView
android:id="#+id/visual_compass_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/measured_bearing"
android:textColor="#aaa"
android:textSize="#dimen/visual_compass_info_text_size" />
</LinearLayout>
</RelativeLayout>
<View
android:id="#+id/placeholder"
android:layout_width="25dp"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/visual_compass_container"
android:visibility="visible"
android:background="#android:color/darker_gray" />
<LinearLayout
android:id="#+id/advanced_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/placeholder"
android:background="#dfff"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="30dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:visibility="visible" >
<TextView
android:id="#+id/advanced_measured"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="#string/measured_bearing_default"
android:textSize="#dimen/advanced_measured_text_size_land" />
<TextView
android:id="#+id/advanced_latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="#string/latitude_default"
android:textIsSelectable="true"
android:textSize="#dimen/advanced_info_text_size_land" />
<TextView
android:id="#+id/advanced_longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="#string/longitude_default"
android:textIsSelectable="true"
android:textSize="#dimen/advanced_info_text_size_land" />
<TextView
android:id="#+id/advanced_altitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="#string/longitude_default"
android:textIsSelectable="true"
android:textSize="#dimen/advanced_info_text_size_land" />
<TextView
android:id="#+id/advanced_accuracy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="#string/accuracy_default"
android:textIsSelectable="true"
android:textSize="#dimen/advanced_info_text_size_land" />
<TextView
android:id="#+id/advanced_declination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="#string/declination_default"
android:textIsSelectable="true"
android:textSize="#dimen/advanced_info_text_size_land" />
<TextView
android:id="#+id/advanced_inclination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="#string/inclination_default"
android:textIsSelectable="true"
android:textSize="#dimen/advanced_info_text_size_land" />
</LinearLayout>
</RelativeLayout>
And the result (API level 17, Galaxy S3) is this:
The Result http://xml.pfweb.eu/a.png
As you can see above, I didn't set any margins or paddings... So why is there an empty space between the placeholder view (dark grey) and the compass rose image?
That's a big problem because it causes the '46°' not the center correctly.
I am unuable to see why the relative layout doesn't wrap it's content, however to have the text in the center you could do following:
<ImageView
android:id="#+id/visual_compass"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:contentDescription="#string/visual_compass"
android:scaleType="fitCenter"
android:src="#drawable/compass_1000x1000_white" />
So instead of having the compass image in top left corner using:
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
you would simply center it. I know it's not ideal, but it's the only solution I see at the moment.
EDIT: I didn't figure out what exactly causes the problem, but it has something to do with the enclosing Relative layout. As soon as I change the layout to Linear the problem disappear. In fact horizontal LinearLayout is probably the best option here as you stack your items from left to right.
Here's final look:

Set TextView width according to other View's width

I have a ImageView, the image is loaded from the net and can vary in width.
Below I have a TextView with a description of the image. I want the TextView to be exactly as wide as the ImageView.
My try was this:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<TextView
android:id="#+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="#style/SmallTextGray" />
</LinearLayout>
which somehow works as the TextView's width is set accoring to that of the ImageView, but the TextView end after 2 lines:
I know I could set the TextView's width programmatically after I know the image's width, but is there also a way to do it in the XML layout?
I don't know if it will work, but try doing in your code, after load the image:
textView.setWidth(imageView.getDrawable().getIntrinsicWidth());
With a small change of layout: replace LinearLayout with a RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/iv"
android:layout_alignRight="#+id/iv"
android:layout_below="#+id/iv"
android:layout_marginTop="8dp"
android:gravity="center_horizontal"
android:textAppearance="#style/SmallTextGray" />
</RelativeLayout>
This way the TextView is always below imageView and its bounds are aligned to imageViews
You can use weight like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
You can use the wight property in xml and give equal weight to both imageview and textview. then both size will be equal
In your case do this:
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_horizontal" />
<TextView
android:id="#+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:textAppearance="#style/SmallTextGray" />
</LinearLayout>
Try This.This will work
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
<TextView
android:id="#+id/imagedescription"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:typeface="monospace" />
</LinearLayout>
</LinearLayout>
This works for me:
<?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:layout_gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/controller"
android:layout_gravity="center_horizontal"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:text="asdasdasasasdasdasdasdasdasdasdadasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdsadasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdsdasdasdasdsadsadsadasdasdsadsadsadasdasdasdasdasdasddasdasdasdasdasdasdasdsadasdasdasdasdasdasdsadasdasdsa..."/>
</TableRow>
</TableLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

LinearLayout: TextViews at left, big ImageView at right

i'm working on a LinearLayout but unfortunately it's not working as it should.
The goal is to have a LinearLayout with two TextViews (one placed below the other) on the left side, and an ImageView on the right side.
The ImageView should be as big as possible, the TextViews should take the remaining space.
At the moment my layout XML is like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="1dp"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dp"
android:orientation="vertical" >
<TextView
android:id="#+id/layout1label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:singleLine="true"
android:text="1234"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/layout2label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1234_label2"
android:textSize="14dp" />
</LinearLayout>
<ImageView
android:id="#+id/layout_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_margin="2dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
The part that isn't working: If the text in the TextViews is "too long", the ImageView gets shrinked. I want it exactly the other way round.
Any solutions?
It would be more efficient to use RelativeLayout instead of LinearLayout. Then you can place your views without having to nest layouts:
<?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" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/image"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/image"
android:layout_below="#+id/title"
/>
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
By arranging the TextViews to be relative to the ImageView instead of the other way around, the ImageView takes priority for the space, and the text works with the remainder.
this might be help to you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="1dp"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/layout1label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:singleLine="true"
android:text="1234"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/layout2label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1234_labj hairu iue rel2"
android:textSize="14dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageView
android:id="#+id/layout_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
A little modification to Kirans Code..worked for me
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/layout1label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:singleLine="true"
android:text="Name: BalaVishnu"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="#+id/layout_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:adjustViewBounds="true"
android:src="#drawable/edit_icon" />
</LinearLayout>

How to make layout of an image and text left and under it?

I need to make a layout which is specific to webpage and it needs to look like a web article with an image and a text left to and under it. Look at the image.
As this is an easy thing to do in a web world, I am not sure how to do it in XML layout.
Obviously, the TextView must be on the left while the image is present, and after it reaches the bottom of the image, it has to stretch to the screen width. I tried this with two TextViews (one for left and another for bottom), but it just does not look right due to the text font size.
EDIT
I also tried to dinamically catch the height of image and then assign it to my TextView, and then make another TextView with the size of the screen under these two elements. This does not work as well as I cannot control the text that is not visible due to limited height of the first TextView.
If you haven't found the answer yet. Here is the same kind of question that is being answered.
How to align TextView around an ImageView?
The only thing what you might have to change in your case is to, make the alignment to be opposite way.
<?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="wrap_content"
android:padding="5dp">
<TextView
android:textSize="18.0sp"
android:id="#+id/message_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text" />
<ImageView
android:src="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/message_view"
android:id="#+id/icon" />
Taken from here,
http://dev.androidteam.ru/snippets/textview/leadingmarginspan2
check out this. it does same as you want
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView4"
android:layout_width="fill_parent"
android:background="#FFFFFF"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:layout_marginTop="5dp"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FFFFFF" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:text="TextView" />
<TextView
android:id="#+id/textView9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
use this way layout
<?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:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="21dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/imageView1"
android:layout_marginLeft="30dp"
android:textColor="#fff"
android:text="TextView" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:text="TextViewaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
android:layout_alignBottom="#+id/textView1"></TextView>
</RelativeLayout>
And add in code
TextView tv1=(TextView)findViewById(R.id.textView1);
tv1.setMaxHeight(maxHeight);
where maxHeight is dynamically get height of imageview
and than put condition to by getting height of textview1 to assign text to second textview
may it helps u
like this am I right?

Categories

Resources