1

Right now, I have a 2x3 table of image buttons and I need to include a TextView at the bottom of the window this is what I have for the TextView:

<TextView
    android:layout_height="wrap_content"
    android:layout_width="match_parent" 
    android:layout_gravity="center_horizontal|bottom"
    android:text = "Hello Connor"
    android:textColor = "#000000"
    android:background = "@drawable/back"/>     
</LinearLayout>
</LinearLayout>
</LinearLayout>

Right now it creates a TextView at the bottom of the screen, however I need the text inside the box to be centered, and I need the name, "Connor" to be bold. How do I go about doing this in 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="vertical"
android:background="@color/all_white">
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
            <ImageButton
                android:background = "@android:color/transparent"
                android:id="@+id/imagebutton1"
                android:src="@drawable/button"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:scaleType = "fitXY"
                android:layout_marginTop = "50px"
                android:layout_marginLeft = "40px"
                android:layout_marginRight = "20px"
                android:layout_marginBottom = "50px"
                android:layout_weight="1"/>
            <ImageButton
                android:background = "@android:color/transparent"
                android:id="@+id/imagebutton2"
                android:src="@drawable/button"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:scaleType = "fitXY"
                android:layout_marginTop = "50px"
                android:layout_marginLeft = "20px"
                android:layout_marginRight = "40px"
                android:layout_marginBottom = "50px"
                android:layout_weight="1"/>
        </LinearLayout>    
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
            <ImageButton
                android:background = "@android:color/transparent"
                android:id="@+id/imagebutton3"
                android:src="@drawable/button"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:scaleType = "fitXY"
                android:layout_marginLeft = "40px"
                android:layout_marginRight = "20px"
                android:layout_marginBottom = "50px"
                android:layout_weight="1"/>
            <ImageButton 
                android:background = "@android:color/transparent"
                android:layout_height="wrap_content"
                android:id="@+id/imagebutton4" 
                android:src="@drawable/button" 
                android:scaleType = "fitXY"
                android:layout_marginLeft = "20px"
                android:layout_marginRight = "40px"
                android:layout_marginBottom = "50px" 
                android:layout_width="wrap_content" 
                android:layout_weight="1"/>
        </LinearLayout> 
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
            <ImageButton 
                android:background = "@android:color/transparent"
                android:layout_height="wrap_content" 
                android:id="@+id/imagebutton5" 
                android:src="@drawable/button" 
                android:scaleType = "fitXY"
                android:layout_marginLeft = "40px"
                android:layout_marginRight = "20px"
                android:layout_marginBottom = "50px"
                android:layout_width="wrap_content"
                android:layout_weight="1"/>
            <ImageButton
                android:background = "@android:color/transparent"
                android:id="@+id/imagebutton6"
                android:src="@drawable/button"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:scaleType = "fitXY"
                android:layout_marginLeft = "20px"
                android:layout_marginRight = "40px"
                android:layout_marginBottom = "50px"
                android:layout_weight="1"/>
        </LinearLayout>
        <TextView
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal|bottom"
        android:text = "Powered by Alarm.com"
        android:textColor = "#000000"
        android:background = "@drawable/back" android:layout_width="match_parent"/>     
    </LinearLayout>
</LinearLayout>
</LinearLayout>
Connor
  • 211
  • 2
  • 8
  • 17

6 Answers6

7

Nevermind, I figured it out. I set the gravity of the textView to center, and set the text to the string "footer" defined in my res/values/strings.xml file as:

<string name="footer">Hello <b>Connor</b></string>

Thanks for the help guys!

Connor
  • 211
  • 2
  • 8
  • 17
0

I think this can only be done in code.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
0

You can use the HTML tags <b> and <i>in strings to mark things bold and italics. As for centering, it seems like your layout is overly convoluted. You'll need to a) simplify it, and b) post the entire layout so we can see why things are the way they are.

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • 1
    I put up the rest of the XML. I just started doing this, this week so I apologize in advance if this makes you want to jump off a cliff. @EboMike – Connor Feb 10 '11 at 18:46
0

You are probably going to be better offer switching to using a RelativeLayout instead of the nested LinaerLayouts. Within a RelativeLayout you can request that an item be centered horizontally.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
0

You might want to consider using a GridView to replicate a 2x3 table and for each element, create a layout containing your TextView with theandroid:layout_gravity="center_horizontal"attribute and inflate this layout for each View in the grid.

take a look at the GridView tutorial to get a headstart with this.

Take a look here fore inflating custom layouts in a view discussion.

Community
  • 1
  • 1
Hakan Ozbay
  • 4,639
  • 2
  • 22
  • 28
0

You can use the HTML tags in your strings.xml file or you can programmatically set to the TextView. For text alignment in center you can use android:textAlignment="center" or android:gravity="center", but in this case make sure that your textView's width is match_parent,if it is wrap_content and better use android:layout_gravity="center"

Rohit Mhatre
  • 241
  • 4
  • 3