2011-02-10 3 views
1

Прямо сейчас у меня есть таблица изображений 2x3, и мне нужно включить TextView в нижней части окна, это то, что у меня есть для TextView:Как разместить текст в 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> 

Сейчас он создает TextView в нижней части экрана, однако мне нужен текст внутри коробки, чтобы быть центром, и мне нужно имя, «Коннор» быть смелыми. Как мне это сделать в 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> 
+2

Глядя на три слова «LinearLayout», я сделал что-то ужасно неправильно с вашим дизайном пользовательского интерфейса. –

ответ

0

Вы можете использовать HTML-теги <b> и <i> в строках, чтобы выделить выделенные жирным шрифтом курсивом. Что касается центрирования, кажется, что ваш макет чрезмерно запутан. Вам нужно: a) упростить его и b) разместить весь макет, чтобы мы могли понять, почему все так, как есть.

+1

Я выставил остальную часть XML. Я только начал делать это, на этой неделе, поэтому заранее извинюсь, если это заставляет вас прыгать с утеса. @EboMike – Connor

0

Возможно, вам лучше предложить перейти на использование RelativeLayout вместо вложенных LinaerLayout. В пределах RelativeLayout вы можете запросить, чтобы элемент был centered horizontally.

0

Возможно, вы захотите использовать GridView для репликации таблицы 2x3 и для каждого элемента, создайте макет, содержащий ваш TextView, с атрибутом android:layout_gravity="center_horizontal" и раздуйте этот макет для каждого вида в сетке.

взгляните на GridView tutorial, чтобы получить головной убор с этим.

Взгляните here Преднамеренное раздувание пользовательских макетов в режиме обсуждения.

+0

Что вы имеете в виду, когда говорите, раздуваете макет? – Connor

+0

читать на LayoutInflater здесь: http://developer.android.com/reference/android/view/LayoutInflater.html –

7

Ничего, я понял. Я установил тяжесть TextView к центру, и установите текст в строке «сноску», определенной в моем Резе/значениях/файл strings.xml как:

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

Спасибо за помощью, ребята!

+0

Не забудьте принять свой собственный ответ. –

Смежные вопросы