guys I tried to add another textview but when I tried the new textview has been placed on the previous textview how can I make the second textview goes down as a new second text view
This is my code I hope you can help me
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:text="#string/state1"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/sayer1"
android:textSize="12sp" />
<TextView
android:id="#+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#id/textView2"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/sayer2"
android:textSize="12sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:text="#string/state2"
android:textSize="16sp" />
</RelativeLayout>
Simple just wrap those two TextView with LinearLayout and slightly align a Bit.
this would be very neat rather than just positioning inside the relative layout. because if you wanna move entire wrap TextView will move alongside. so you don't need to worry about aligning each TextView
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/state1"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="#id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/sayer1"
android:textSize="12sp" />
</LinearLayout>
You should only align one TextView based on the parent and the rest based on that one.
Or put in other words, if you are not setting a layout_ parameter, then you should align it with the parent so the view knows where to position itself. Now, the other views can use layout_ parameters against the view that has an alignParent parameter.
If you align all of them against the parent, they will just align keeping the parent in mind and not bother about the other TextViews.
I like to imagine that they view that is aligned with the parent is a sort of "anchor" and the other ones position themselves against it.
Try the following (I removed the to other parameters for readability not because you should remove them!)
<TextView
android:id="#+id/textView1"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/secondLine"
android:layout_below="#id/textView1" />
//If You set it below, there's no reason to align it with the Parent
// you can now use margins instead
<TextView
android:id="#+id/thirdLine"
android:layout_below="#id/textView2" />
//Same scenario
<TextView
android:id="#+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
//In this case you DO need to align with parent because you are not setting a
//layout_ parameter
I hope this helps guide you in the right direction. Also, keep in mind that if you change the values on the views with alignParent parameter, the other views that have a layout_ parameter and will also change in position.
Change your xml file to following. It might help you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="vertical"
android:padding="6dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/state1"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/sayer1"
android:textSize="12sp" />
<TextView
android:id="#+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/sayer2"
android:textSize="12sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/state2"
android:textSize="16sp" />
</LinearLayout>
Related
I've got an issue with my TextView, I just can't center it. Here's what it should look like :
And it's actually look like that
Here's my XML code
<?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/magnitudeTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_margin="10dp"
android:textSize="15sp" />
<TextView
android:id="#+id/cityNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:textSize="15sp" />
<TextView
android:id="#+id/dateTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:textSize="15sp" />
</RelativeLayout>
Using a LinearLayout with horizontal orientation along with a weightsum of 3 for the children text view would give you a light and more reliable solution, doing it like the following:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3"
android:orientation="horizontal">
<TextView
android:id="#+id/magnitudeTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="test"
android:textSize="15sp" />
<TextView
android:id="#+id/cityNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:gravity="center"
android:layout_weight="1"
android:layout_margin="10dp"
android:textSize="15sp" />
<TextView
android:id="#+id/dateTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="10dp"
android:textSize="15sp" />
</LinearLayout>
Now each of your text views will take exactly 1/3 of the whole screen width, if you want the center one to be bigger you can play with the layout_weight value in each of the text view to match your desired design.
Instead of RelativeLayout you can use LinearLayout in which you can set the weightsum to 3 that will give you more reliable solution. Every TextView will get the equal amount of space in a row.
The Below technique work for me.That is:
Use your first TextView as left orient and middle TextView as center oriented and last TextView as right oriented and apply weight for each TextView.
Your code it would be 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"
orientation=vertical
weightsum=3
>
<TextView
android:id="#+id/magnitudeTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_margin="10dp"
android:textSize="15sp"
android:layout_weight=1 />
<TextView
android:id="#+id/cityNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="15sp"
android:layout_weight=1/>
<TextView
android:id="#+id/dateTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:textSize="15sp"
android:layout_weight=1/>
</LinearLayout>
`
A horizontal LinearLayout would provide a better and lighter solution for your problem. What you'd do is wrap your three textviews in it, then use layout_width=wrap_content for the ones to the left and right and layout_width=0dp
layout_weight=1
for the middle one
Generally, a linear layout with weights would suit these kinds of needs, the system will automatically divide the screen into parts depending on the weightsum you mentioned
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum = "5"
android:orientation = "horizontal"
/>
<TextView
android:id="#+id/magnitudeTV"
android:layout_width="0dp"
android:layout_weight = "1"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_margin="10dp"
android:textSize="15sp" />
<TextView
android:id="#+id/cityNameTV"
android:layout_width="0dp"
android:layout_weight = "3"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:textSize="15sp" />
<TextView
android:id="#+id/dateTV"
android:layout_width="0dp"
android:layout_weight = "1"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:textSize="15sp" />
</LinearLayout>
You can achieve this by doing this :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true">
<TextView
android:id="#+id/magnitudeTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="sdf34 "
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:id="#+id/cityNameTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/magnitudeTV"
android:layout_margin="10dp"
android:text="dasdasdsadasdds"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:layout_toRightOf="#id/cityNameTV"
android:id="#+id/dateTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="fg25111dfg"
android:textColor="#000000"
android:textSize="15sp" />
</RelativeLayout>
but according to me it is not a good solution for this you can con-catenate all the three strings and than set the final string to one single text view as mentioned below:
String final_string = distance +" "+string_2 +" "+string_3;
textView.setText(final_string);
i added a second TextView and it is supposed to be beneath the first TextView but now the first TextView is working but the second one isn't showing up.
This is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/state1"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="#id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="#string/sayer1"
android:textSize="12sp" />
<TextView
android:id="#+id/thirdLine"
android:layout_below="#+id/textView2"
android:text="#string/state2"
android:textSize="16sp" />
<TextView
android:id="#+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/sayer2"
android:textSize="16sp" />
</RelativeLayout>
You need three things to make the others appear.
First:
Change this attribute android:layout_height="?android:attr/listPreferredItemHeight" to android:width="match_parent"
Second:
Set a width/height to your TextViews. thirdLine and textView2 haven't a proper width/height. Try to make this:
android:layout_width="match_parent"
android:layout_height="wrap_content"
Finally:
Don't try to place a TextView below another which its alignment is alignParentBottom. Instead of this, try to add a container which its aligment is at the bottom of the global parent. See below:
Try this formatting:
<?xml version="1.0" encoding="utf-8"?>
// set a height to wrap_content/match_parent/fill_parent
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="state1"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="#id/textView1"
android:ellipsize="end"
android:singleLine="true"
android:lines="1"
android:text="sayer1"
android:textSize="12sp" />
// if you want to align the latter text
// to the bottom, make a container as...
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
// declare the width/height of the TextView
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:text="sayer2"
android:textSize="16sp" />
<TextView
android:id="#+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="#+id/textView2"
android:text="state2"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
Let me know if it's the expected result. Hope this helps.
It might be that your top RelativeLayout has its height set to ?android:attr/listPreferredItemHeight and the first text views height is set to wrap content. Depending on the height of the first text view it could just be that the layout isn't high enough to show both
Change your top RelativeLayout to use a height of wrap_content
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dip" >
Looking at these two text views:
<TextView
android:id="#+id/thirdLine"
android:layout_below="#+id/textView2"
android:text="#string/state2"
android:textSize="16sp" />
<TextView
android:id="#+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/sayer2"
android:textSize="16sp" />
This will not work as you are putting the second one at the bottom with layout_alignParentBottom="true" and then you're trying to put something underneath it. But its aligned to the bottom so there is no space below it!
Changing those bottom two text views to following might do what you want:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:text="#string/sayer2"
android:textSize="16sp" />
<TextView
android:id="#+id/thirdLine"
android:text="#string/state2"
android:textSize="16sp" />
</LinearLayout>
I don't think the layout you have works properly, you should be getting a "no resource found..." against #id/textView2 since you are trying to reference it in
android:layout_below="#id/textView2"
within your "thirdLine" TextView BEFORE you have added the textView2 into the relativelayout.
The order should be like this:
<TextView
android:id="#+id/textView1"" />
<TextView
android:id="#+id/secondLine"
android:layout_below="#id/textView1" />
<TextView
android:id="#+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" " />
<TextView
android:id="#+id/thirdLine"
android:layout_below="#+id/textView2" />
Do remember that when you have RelativeLayout the order in which you add your views doesn't matter, you can tell them where to position themselves.
What must always happen though is that you if you are referencing a view, it must be above the view that is referencing it. Wow that's confusing.
Let's say A wants to be below B. Then in your RelativeLayout, B must come BEFORE A.
Now that that's explained. In your textView2 you have told it to align itself against its parent so that it goes to the bottom and left. Of course you can't have thirdLine below textView2 since textView2 is aligned in bottom left. Try instead:
<TextView
android:id="#+id/thirdLine"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/textView2"
android:layout_above="#+id/thirdLine" />
Also, isn't the IDE telling you to state "layout_width" and "layout_height"? For the TextViews. If this hasn't helped you at all, could you please draw a small picture of what you need so we may guide you better?
I'd also suggest stating the parent view's (Your RelativeLayout) height and width to "fill_parent" (API 7 and below) or "match_parent" (API 8 and above).
For the other views I'd go for
android:layout_width="match_parent" or "fill_parent"
android:layout_height="wrap_content"
But you can also have the width set to "wrap_content" whatever suits your UI better.
NOTE: I've been advised that this answer is wrong, but it does highlight an issue in the layout simulator parser. In that light, I'm going to leave this answer in-tact to document the flaw.
You accdententally added #+id/TextView2 to the layout below.
android:layout_below="#+id/textView2"
Try this instead to reference the concrete id, and you'll need to add sizing parameters
<TextView
android:id="#+id/thirdLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView2"
android:text="#string/state2"
android:textSize="16sp" />
This works with only these changes in my android layout simulator, but you might need to move the definition textView2 to be above where it's referenced.
Here's the file as it works in my layout builder:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="asdf"
android:textSize="16sp" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="#id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="fdsa"
android:textSize="12sp" />
<TextView
android:id="#+id/thirdLine"
android:layout_below="#id/textView2"
android:text="asdffdsa"
android:textSize="16sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="string/sayer2"
android:textSize="16sp" />
</RelativeLayout>
Here is what is looks like and here is my XML code.
Can someone please post the fixed XML layout code for me and explain what I am doing wrong? I want the - symbol on the left to be all of the way left, just like the > symbol on the right side. The black text should be just to the right of the - symbol.
<?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="wrap_content">
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="44dip"
android:stretchColumns="0"
android:divider="#null"
>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/infocells"
android:divider="#null" >
<ImageView
android:id="#+id/imgDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/minus" />
<TextView
android:id="#+id/txtKey"
android:text="Some text"
android:textSize="16dip"
android:textStyle="bold"
android:layout_marginLeft="8dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:layout_weight="1.0"
android:layout_marginTop="11dp"
android:layout_marginBottom="6dp"
android:textColor="#color/black"
/>
<TextView
android:id="#+id/txtValue"
android:text="Some text"
android:textSize="16dip"
android:layout_marginRight="8dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|center_vertical"
android:layout_weight="1.0"
android:layout_marginTop="11dp"
android:layout_marginBottom="6dp"
android:textColor="#color/darkblue"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_marginTop="7dp"
android:layout_marginRight="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow" />
</TableRow>
</TableLayout>
</LinearLayout>
Why don't you make use of RelativeLayout and using various property of it you can align your TextView and ImageView according to your other views.If u want to set a - to the left then make use android:layout_alignParentLeft="true" and android:layout_alignParentLeft="true" for you > to set it to the right of the layout
In your ImageView you can set your X position using translationX like something below:
<ImageView
android:id="#+id/imgDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationX="-25"
android:src="#drawable/minus" />
Just try it. This is a quick solution only.
Here's an idea on how you can do it. Give it a try.
<RelativeLayout>
<ImageView
android:id="#+id/imgDelete"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/txtKey"
android:layout_toRightOf="#+id/imgDelete" />
<TextView
android:id="#+id/txtValue"
android:layout_toRightOf="#+id/txtKey" />
<ImageView
android:id="#+id/imageView1"
android:layout_alignParentRight="true" />
</RelativeLayout>
I have an ImageView aligned to the parent right in a relativeLayout.
Here is my layout:
<RelativeLayout android:id="#+id/row" android:background="#null" style="#style/ListRow"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:textStyle="bold" android:textColor="#color/primary_text" android:text="Username" android:gravity="center_vertical" android:id="#+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:layout_toLeftOf="#id/avatar" />
<LinearLayout android:gravity="center_vertical" android:id="#+id/time_item" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="#id/username" android:layout_alignBottom="#id/username" android:layout_alignParentLeft="true">
<TextView android:textSize="#dimen/font_size_small" android:text="12:00AM" android:textColor="#color/secondary_text" android:gravity="center_vertical" android:id="#+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout android:id="#+id/avatar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5.0dip" android:layout_alignParentRight="true">
<ImageView android:id="#+id/picture" android:src="#drawable/ic_launcher" android:layout_width="48.0dip" android:layout_height="48.0dip" android:scaleType="center" android:adjustViewBounds="true" />
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" />
</RelativeLayout>
<TextView android:textSize="#dimen/font_size_small" android:text="aslkndalskndlaksndlaskndlaksnlansldnaslkndalsdnaslkdnls" android:textColor="#color/primary_text" android:id="#+id/body" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toLeftOf="#id/avatar" android:layout_below="#id/username" android:lineSpacingMultiplier="1.2" />
</RelativeLayout>
Here is what it looks like:
When starting a new line of text I want the text to align on to the right instead of the left. I have photoshopped what I want. Here is what I want:
Anyone know how I should modify my layout to where it does this? Thanks!
Just add one more property in your TextView body.
android:gravity="right"
You are missing the android:gravity="right" element from your TextView Body. It should go like
<TextView android:gravity="right"...
That simply makes the text originate on the right side of the TextView
I dont quite get the layout of my List View Item doesnt show like I want it to.
I hope somone would give me some hints since i cannot make it work for quite some time now.
What i want is as follows:
Here is my approach:
<?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="20dip"
android:padding="6dip">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="3dip">
<TextView
android:id="#+id/nametext"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="7dip">
<ImageView
android:id="#+id/photo"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="#drawable/icon" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="#+id/toptext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="#+id/middletext"
android:singleLine="true"
android:ellipsize="marquee"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="#+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
/>
</LinearLayout>
<ImageView
android:id="#+id/stars"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="6dip"
android:src="#drawable/icon" />
</LinearLayout>
Any help would be appreciated.
I already tried different sizes and a RelativeLayout. No change.
It doesnt look anythik like i thought it should.
edit three blanks missing
edit2 added pic
You could do this with LinearLayouts, but you'll need three nested layouts:
A vertical LinearLayout containing everything.
A horizontal LinearLayout containing everything aside from the heading.
A vertical LinearLayout containing the non-heading TextViews.
The inner vertical LinearLayout will probably need android:layout_weight="1" so it stretches to fill the available space but doesn't squeeze out the right-hand ImageView.
That's all very expensive, particularly when multiplied by the numerous views in a ListView. A RelativeLayout can get this done with only one 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="wrap_content"
android:padding="6dip" >
<TextView
android:id="#+id/textView1"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:textSize="40sp">
</TextView>
<ImageView
android:id="#+id/imageView1"
android:layout_below="#+id/textView1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon" >
</ImageView>
<ImageView
android:id="#+id/imageView2"
android:layout_below="#+id/textView1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon" >
</ImageView>
<TextView
android:id="#+id/textView2"
android:layout_below="#+id/textView1"
android:layout_toRightOf="#+id/imageView1"
android:layout_toLeftOf="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="TextView" >
</TextView>
<TextView
android:id="#+id/textView3"
android:layout_below="#+id/textView2"
android:layout_toRightOf="#+id/imageView1"
android:layout_toLeftOf="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="TextView" >
</TextView>
<TextView
android:id="#+id/textView4"
android:layout_below="#+id/textView3"
android:layout_toRightOf="#+id/imageView1"
android:layout_toLeftOf="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="TextView" >
</TextView>
</RelativeLayout>
Edited for formatting and to add:
This is the result. Of course, text and image sizes need adjusted, but the basic result is what you've described.
Im not sure if you really want to have a 3dip headline and 7dip content...
if you want the stuff inside the outer linearlayout vertical arranged, use
android:orientation="vertical"
in the parent LinearLayout. to arrange the three items in the content part of your layout, you might use android:weight or android:alignParentLeft / Right.
I fear im not sure waht you want to do, so i can not edit your layout :(