2015-11-19 2 views
0

Я пытаюсь передать текст, возвращенный с сервера в пользовательском интерфейсе. я получил доступ к данным, но по какой-то причине моя дата (textViewDate) не начинается с других строк, таких как place (textViewPlace) и времени (textViewTime). Как я могу привести его в соответствие?Как выровнять текст в текстовом объекте Объект в Android

это мой XML-код:

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/relativlayoutGcmMessage" 
    android:background="#ffffff"> 

    <TextView 
     android:id="@+id/message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="this is the message" 
     android:textSize="20sp" 



     android:layout_below="@+id/textViewUser" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_above="@+id/textViewloc" /> 

    <LinearLayout 
     android:id="@+id/linearLayoutBtn" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:baselineAligned="false" 
     android:layout_marginTop="20dp" 
     android:layout_below="@+id/separatorDown" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <Button android:text="Join" 
      android:id="@+id/ButtonJoin" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 

      android:textColor="#ffffff" 
      android:background="#606060" 
      android:layout_below="@+id/linearLayoutBtn" 
      android:layout_toRightOf="@+id/textViewUser" 
      android:layout_toEndOf="@+id/textViewUser"> 
     </Button> 

    </LinearLayout> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dp" 
     android:id="@+id/separatorUp" 
     android:visibility="visible" 
     android:background="#FF0000" 
     android:layout_marginTop="25dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 
    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dp" 
     android:id="@+id/separatorDown" 
     android:visibility="visible" 
     android:background="#FF0000" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="User ," 
     android:id="@+id/textViewUser" 
     android:layout_below="@+id/separatorUp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:textStyle="bold" 
     android:layout_marginTop="5dp" 
     android:textSize="20sp" 
     android:textColor="#000000" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="When:" 
     android:id="@+id/textViewWhen" 
     android:textStyle="bold" 
     android:textSize="20sp" 
     android:textColor="#000000" 
     android:layout_above="@+id/separatorDown" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginBottom="45dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Date" 
     android:id="@+id/textViewDate" 
     android:textSize="20sp" 
     android:layout_marginLeft="40dp" 
     android:layout_alignTop="@+id/textViewWhen" 
     android:layout_toRightOf="@+id/textViewUser" 
     android:layout_toEndOf="@+id/textViewUser" /> 

    <Button android:text="Deny" 
     android:id="@+id/ButtonDeny" 
     android:layout_width="361dp" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 

     android:textColor="#ffffff" 
     android:background="#606060" 
     android:layout_below="@+id/linearLayoutBtn" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

    </Button> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Between:" 
     android:id="@+id/textViewbtwn" 
     android:textColor="#000000" 
     android:textStyle="bold" 
     android:textSize="20sp" 
     android:layout_below="@+id/textViewDate" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Time" 
     android:id="@+id/textViewtime" 
     android:layout_marginLeft="10dp" 
     android:textSize="20sp" 
     android:layout_below="@+id/textViewDate" 
     android:layout_toRightOf="@+id/textViewbtwn" 
     android:layout_toEndOf="@+id/textViewbtwn" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Location:" 
     android:id="@+id/textViewloc" 

     android:layout_above="@+id/textViewWhen" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:textStyle="bold" 
     android:textColor="#000000" 
     android:textSize="20sp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="place" 
     android:id="@+id/textViewPlace" 
     android:layout_above="@+id/textViewDate" 
     android:layout_alignLeft="@+id/textViewtime" 
     android:layout_alignStart="@+id/textViewtime" 
     android:textSize="20sp" /> 

</RelativeLayout> 

это, как его внешний вид, как на моем устройстве: enter image description here

+0

Добавить Центр тяжести. – Destro

+0

добавить его onlt в textViewDate или для всех трех текстовых экранов? –

+0

все же я получил тот же результат. –

ответ

1

Добавить layoute Как это:

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Date" 
    android:id="@+id/textViewDate" 
    android:textSize="20sp"   
    android:layout_alignTop="@+id/textViewWhen" 
    android:layout_toRightOf="@+id/textViewUser" 
    android:layout_toEndOf="@+id/textViewUser" /> 

В этом коде есть Удалить эту линию ..

android:layout_marginLeft="40dp" 

Я думаю, что его работа.

+0

спасибо, что он сработал для меня. –

0

Используйте макет таблицы

<TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Location:" 
       /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="place" 
       /> 
     </TableRow> 
     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="When:" 
       /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Date" 
       /> 
      </TableRow> 
     <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Between:" 
       /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Time" 
       /> 
     </TableRow> 
    </TableLayout> 

Также удалить свойство маржу от DATE текста.

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