tags:

views:

103

answers:

2

I have the following in a TableRow:

        <TextView 
            android:text="Current" 
            android:id="@+id/theScreen" 
            android:layout_width="wrap_content" 
            android:padding="2px" 
            android:typeface="monospace" 
            android:textStyle="bold" 
            android:gravity="enter_vertical|center_horizontal">
        </TextView>

        <ImageView 
            android:id="@+id/rightArrow" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:focusable="false"
            android:padding="2px"
            android:src="@drawable/right_arrow">
        </ImageView>

The image in the ImageView is 26 pixels high. I want the text in the TextView to be centered both horizontally and vertically. It is centered but stays at the top of the box. I'm sure I'm overlooking something stupid... Thanks!

A: 

You are missing a "c" in center_vertical?

Mayra
Feel free to vote up my comment that already says this.
kiswa
It wouldn't compile ...
fedj
opps, copy past error, the c is there
cbursk
A: 

How do you inflate your view ? inflate(id, parent, false) ? otherwise try

fedj
so far I'm just creating the xml files and then using the layout editor in Eclipse to review what it looks like
cbursk
Ah, don't trust what the layout editor says as truth. You need to actually run it and see what it looks like in the emulator before you can say it doesn't work.
Mayra
Mayra is completely true, don't trust the layout editor, it's just a temporary help but it sometimes goes wrong.
fedj
I'm getting the same results viewing in my AVD. The code snippet above is missing another ImageView. Basically I have a TextView in between the two Images which are 26 pixels high. These are in a row across the screen. The Text is center left and right, but stays at the top of the space.
cbursk
Your TextView is width="wrap_content" and your height might be 0 so your TextView is not as large as you might think.
fedj
Rock on! The height was the issue. I updated the layout_height of the TextView to be fill_parent and that corrected the issue. Thank you!
cbursk