creating buttons for dashboard, problems with onClick, maybe better solution? - java

I am currently implementing my dashboard. My current solution for buttons is this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="33"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#drawable/button_frame"
android:id="#+id/viewAddItemBtn"
android:onClick="BtnListener"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/addbutton"
/>
<TextView
android:text="Add Item"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
/>
</LinearLayout>
However, I now have some problems with 1. the "clickability" and the states (focused/pressed/normal).
As you might guess out of my code: If i click on the "ImageButton" (which could basically be a imageview too on solution) it does nothing. (because onClick is not assigned, I thought it would inherit the attribute from its overall LinearLayout). Second thing is, if I make the "ImageButton" Clickable too, i guess the states won't be called, am I right here?
is there any better solutions for my design?
little demo-picture on how the button should look like: http://i.imgur.com/aI2Vb.png

Why do not you add the onClick property for all of the components:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="33"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#drawable/button_frame"
android:id="#+id/viewAddItemBtn"
android:onClick="BtnListener"
>
<ImageButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/addbutton"
android:onClick="BtnListener"
/>
<TextView
android:text="Add Item"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:onClick="BtnListener"
/>
</LinearLayout>

Related

Android: Why doesn't my second TextView show up, while the first one does?

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>

Add another textview under the previous textview as a second textview

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>

TextView not being displayed / Relative Layout

This might seem like a very easy question for some of you folks, but I can't find a way to display my TextView even after trying numerous solutions proposed on this site. Not that I am using the built-in Eclipse XML tool for Android and that the TextView is visible on this graphical layout. Here's what I've got so far :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:contentDescription="#string/no_of_screens"
android:id="#+id/imageViewHome"
android:layout_width="290dp"
android:layout_height="212dp"
android:layout_gravity="center_horizontal"
android:paddingTop="40dp"
android:src="#drawable/logo" />
<RelativeLayout
android:id="#+id/relativeid"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/launch_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="80dp"
android:text="#string/launch" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/launch_button"
android:layout_marginRight="20dp"
android:layout_toLeftOf="#+id/launch_button"
android:entries="#array/num_array"
android:prompt="#string/screen_prompt"
android:textSize="8pt" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/launch_button"
android:layout_alignBottom="#+id/launch_button"
android:layout_marginRight="16dp"
android:layout_toLeftOf="#+id/spinner1"
android:text="#string/no_of_screens"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
As for now, all of the other elements are being displayed correctly. Any help would be greatly appreciated!
Thanks
Where do you want your textView?
I would loose these two:
layout_alignBaseline="#+id/launch_button
layout_alignBottom="#+id/launch_button
and use one of these:
layout_below="#+id/launch_button
layout_above="#+id/launch_button
That will put it either above or below the button.

Android Custom ListViewItem Layout

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 :(

android:layout_gravity doesn't work as expected

I have a simple LinearLayout with one TextView and one ImageView. I want the text in the TextView to be aligned to the right, but the result show that the Text was aligned to the left. Is there anything wrong with my layout xml? Thanks.
<?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="wrap_content" android:background="#E8E3E4">
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
>
<TextView android:layout_width="260dp" android:layout_height="wrap_content"
android:text="More Comments" android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:layout_gravity="right" />
<ImageView android:layout_width="50dp"
android:layout_height="wrap_content" android:src="#drawable/arrow_right"
android:layout_gravity="center" android:scaleType="centerInside" />
</LinearLayout>
</LinearLayout>
Thanks, Michael. But the workaround you mentioned doesn't work either.
I tried to use RelativeLayout, but it still gave me result like:
More Comments (Icon)
What I expected is
More Comments (Icon)
The RelativeLayout xml is below. Is there anything wrong with it?
<?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">
<TextView android:id="#+id/label" android:layout_width="260dp"
android:layout_height="wrap_content" android:text="More Comments"
android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:layout_gravity="right" />
<ImageView android:layout_width="50dp" android:layout_height="wrap_content"
android:src="#drawable/arrow_right" android:layout_gravity="center"
android:scaleType="centerInside" android:layout_toRightOf="#id/label" />
</RelativeLayout>
Following the workaround in Michael's comment, I have the XML below. I expected the output to be:
RightLeft
but the actual output is:
Right Left
So the workaround doesn't work for me. Any thoughts?
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1.0"
android:text="RIGHT"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="LEFT"/>
</LinearLayout>
LinearLayouts with a horizontal orientation don't support right/left gravity. You can find a workaround here.
I figured out what is wrong with my xml. I should have used gravity instead of layout_gravity to right-align the text in TextView. The following XML works as expected.
<?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">
<TextView android:id="#+id/label" android:layout_width="260dp"
android:layout_height="wrap_content" android:text="More Comments"
android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:gravity="right" />
<ImageView android:layout_width="50dp" android:layout_height="wrap_content"
android:src="#drawable/arrow_right" android:layout_gravity="center"
android:scaleType="centerInside" android:layout_toRightOf="#id/label" />
</RelativeLayout>
I've done only a few projects with android, but android:layout_gravity specifies the alignment for the View within the parent, android:gravity specifies the alignment of the Views contained within the View whose gravity you are specifying. Make sure you have the proper one specified. The documentation does not distinguish between these two.
It would be easier to help you if you posted some sample XML.
EDIT:
I see you have posted the XML now. It does look like you have the proper attribute set, but if you are aligning the text to the right, why would you put it first in the linear layout? I suggest changing it to go left to right.
Here is some code I wrote for my project. It accomplishes what you're looking for. I'd just change the control types and such and you should be off and running.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#ffdddddd">
<TextView android:layout_width="260dp"
android:layout_height="wrap_content"
android:text="More Comments"
android:textStyle="bold"
android:background="#ff0000"
android:textColor="#121222"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<ImageView android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="#drawable/arrow_right"
android:scaleType="centerInside"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>

Categories

Resources