2016-12-02 4 views
0

Я хочу реализовать следующую схему:
enter image description hereКак лежать горизонтально эти виды?

Я сделал это следующим образом:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:orientation="horizontal" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:layout_marginRight="20dp" 
    > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="LABEL" 
      android:textSize="14sp" 
      android:layout_marginBottom="5dp" 
     /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/white" 
      android:padding="10dp" 
      android:text="Text Box 1" 
      android:textSize="14sp" 
     /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
    > 
     <LinearLayout android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:orientation="vertical" 
     > 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="LABEL 2" 
       android:layout_marginBottom="5dp" 
       android:textSize="14sp" 
      /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="horizontal" 
      > 
       <TextView 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:text="BLA-1" 
        android:background="@color/white" 
        android:textSize="14sp" 
       /> 

       <TextView android:layout_width="wrap_content" 
          android:layout_height="match_parent" 
          android:layout_marginLeft="10dp" 
          android:layout_marginRight="10dp" 
          android:gravity="center|bottom" 
          android:text="and" 
          android:textSize="14sp" 
       /> 

       <TextView 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:text="BLA-2" 
        android:background="@color/white" 
        android:textSize="14sp" 
       /> 


      </LinearLayout> 

     </LinearLayout> 

    </LinearLayout> 

</LinearLayout> 

В основном я использовал LinearLayouts и гравитацию.
Это работает, но кажется сложным, и я заметил, что когда я увеличиваю поля слева и справа от текста and, тексты BLA-1 и BLA-2 обрезаются.
Есть ли лучший способ для этого?
Я думаю, что я не могу использовать относительный макет, так как я не смог бы, чтобы представления занимали эти размеры по экрану, верно?

UPDATE:
Также с моим подходом любой вид прокладки в TextViews отсекает текст

+0

Проверьте мой ответ ниже, и дайте мне знать, если вы сталкиваетесь с каким-либо вопросом. –

+0

Вы проверили мой ответ? это работает или нет? дайте мне знать, если вы столкнетесь с любым вопросом, сэр. –

ответ

0

Это выглядит так же, как на скриншоте (просто настроить цвета)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:padding="16dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

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

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#FFF" 
      android:hint="Text Box 1" 
      android:padding="4dp" 
      android:textColorHint="#757575" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="wrap_content" 

      android:layout_height="wrap_content" 
      android:text="LABEL2" /> 

     <LinearLayout 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

      <EditText 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="#FFF" 
       android:hint="BLA-1" 
       android:padding="4dp" 
       android:textColorHint="#757575" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="4dp" 
       android:layout_marginRight="4dp" 
       android:text="and" /> 

      <EditText 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="#FFF" 
       android:hint="BLA-2" 
       android:padding="4dp" 
       android:textColorHint="#757575" /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 
+0

Нет, это не то же самое. Я хочу, чтобы в тексте было больше места. С вашим фрагментом они «сжимаются» вместе. Я протестировал его – Jim

+0

Эй, Джим, у какого TextView должно быть больше места? Не могли бы вы показать мне, как они сжимаются вместе на скриншоте? – stasbar

0

Я думаю, LinearLayout - хороший выбор, хотя он сложный, если вы хотите сохранить вес. Вы должны изменить все свои TextView s на wrap_content, чтобы они не обрезались. Если вы все еще хотите, чтобы избежать пробелов вы можете обернуть каждый TextView с LinearLayout или FrameLayout, как это:

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="LABEL2" /> 
</LinearLayout> 
+0

Если я использую 'wrap_content', то текстовые поля« сжимаются », я хочу, чтобы они расширялись полностью, как на скриншоте – Jim

0

Здесь вы можете получить его с помощью Linear Layout. Посмотрите ниже 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="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:orientation="horizontal" 
     android:weightSum="3" 
     tools:ignore="DisableBaselineAlignment"> 

     <LinearLayout 
      android:id="@+id/llOne" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.5" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="5dp" 
       android:text="LABEL" 
       android:textSize="14sp" /> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/white" 
       android:hint="textbox1" 
       android:padding="10dp" 
       android:textSize="14sp" /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/llTwo" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.6" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="5dp" 
       android:text="LABEL" 
       android:textSize="14sp" /> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/white" 
       android:hint="BLA1" 
       android:padding="10dp" 
       android:textSize="14sp" /> 

     </LinearLayout> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center|bottom" 
      android:layout_marginBottom="5dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_weight="0.3" 
      android:text="and" 
      android:textSize="14sp" /> 

     <LinearLayout 
      android:id="@+id/llThree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center|bottom" 
      android:layout_weight="0.6" 
      android:orientation="vertical"> 


      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/white" 
       android:hint="BLA2" 
       android:padding="10dp" 
       android:textSize="14sp" /> 

     </LinearLayout> 

    </LinearLayout> 

</RelativeLayout> 

enter image description here

+0

Этот подход имеет тот же конечный результат, что и мой. Он обертывает текст. Также, как вы выбрали весы, мне непонятно – Jim

+0

@Jim Не могли бы вы показать мне результат, когда он обертывает текст. Поведение веса поддерживается на основе * весовой суммы *. –

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

  • Нет связанных вопросов^_^