Макет с двумя TextViews - PullRequest
       3

Макет с двумя TextViews

1 голос
/ 08 марта 2012

Я пытаюсь создать макет с двумя TextView:

|                                                     |
| (Multilined Textview) (60dp TextView)               |
| (of unknown size    )                               |

Если в первом TextView мало текста, он должен выглядеть следующим образом:

|                                                     |
| (Hello!) (12:34:56)                                 |
|                                                     |

Если первый TextView имеетмного текста, это должно выглядеть так:

|                                                     |
| (Ey! This is a very very very very long) (12:34:56) |
| (message.                              )            |

Кто-нибудь знает, как этого добиться?

Большое спасибо.

РЕДАКТИРОВАТЬ: Я получил это работает.Решение в моем собственном ответе.

Ответы [ 4 ]

3 голосов
/ 08 марта 2012

Я полагаю, что вы можете достичь этого с помощью взвешенного LinearLayout:

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:weightSum="1">

  <TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1" />

  <TextView
    android:layout_width="60dp"
    android:layout_height="wrap_content"
    android:layout_weight="0" />

</LinearLayout>

Обновление: Альтернативное решение, которое вы также можете попробовать (возможно, даже в сочетании с взвешеннымLinearLayout):

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxWidth="200dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>
1 голос
/ 08 марта 2012

Попробуйте это:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >    
    <TextView
        android:id="@+id/text_1"
        android:layout_width="wrap_content" 
        android:padding_right = 'fix value of width of TextView text 2'
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:gravity="left" />
    <TextView
        android:id="@+id/text_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/text_1"
        android:gravity="center" />
</RelativeLayout>
0 голосов
/ 21 апреля 2012

Здесь я положил свое окончательное решение:

<TextView
    android:id="@+id/variable_size_textview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:paddingRight="60sp" />

<TextView
    android:id="@+id/hack"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_toRightOf="@+id/variable_size_textview" />

<TextView
    android:id="@+id/fixed_size_textview"
    android:layout_width="60sp"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/hack" />

0 голосов
/ 08 марта 2012

Вы должны использовать android:layout_width="wrap_content".Если ваше текстовое представление инициализируется пустой строкой, вы должны использовать android:minHeight="100dp", чтобы также установить минимальную ширину.

...