2016-10-13 4 views
1

Есть ли более простой (лучший) способ сделать этот макет? Может быть, с ConstraintLayout?Есть ли лучший способ сделать этот макет? Может быть, с помощью Constraint Layout?

3333 должен быть всегда в нижнем правом углу, и 2222 под 1111.

Не уверен, что, если есть лучший способ использовать один RelativeLayout или FrameLayout?

Я пробовал конструкцию Constraint, но Android Studio немного сходит с ума при перемещении элементов.

ScreenShot layout

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true"> 

<LinearLayout 
    android:id="@+id/LeftLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentStart="true" 
    android:layout_centerVertical="true" 
    android:layout_margin="10dp" 
    android:layout_toStartOf="@+id/textView3" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:maxLines="2" 
     android:text="11111111111111111111111111111111111111111111111111111111" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:maxLines="1" 
     android:text="222222222" 
     android:visibility="visible" /> 

</LinearLayout> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="3333" 
    android:layout_alignBottom="@+id/LeftLayout" 
    android:layout_alignParentEnd="true" />  
</RelativeLayout> 

ответ

1

Использование ConstraintLayout, вы можете создать представление текста, содержащего «111» с его шириной установлен в MATCH_CONSTRAINT (0dp), высота установки до MaxLines и WRAP_CONTENT. Затем ограничьте его слева и сверху родительского элемента, а справа ограничено представлением, содержащим «3333». Вид с «222» просто ограничен снизу «111» по вертикали и слева от родителя. «333» затем просто ограничивается нижним и правым родительским.

like this

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:padding="8dp" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/textView7" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="1111111111111111111111111111111111111111111111111111111111" 
     android:maxLines="2" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/textView8" /> 

    <TextView 
     android:id="@+id/textView9" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="2222222222" 
     app:layout_constraintTop_toBottomOf="@+id/textView7" 
     app:layout_constraintLeft_toLeftOf="parent" /> 

    <TextView 
     android:id="@+id/textView8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="3333" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintRight_toRightOf="parent" /> 

</android.support.constraint.ConstraintLayout> 
1

Вы можете использовать LinearLayout с весами для такого рода сценариев.

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

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

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="11111111111111111111111111111111111111111" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="2222222222" /> 
    </LinearLayout> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:gravity="bottom" 
     android:text="3333" /> 
</LinearLayout> 
+0

Таким образом, существует всего лишь 3 TextView (не 4), также 3333 должен быть в правом нижнем углу. Поэтому вам нужно добавить android: gravity = "bottom" и android: layout_height = "match_parent" в текст 3333. Мой вопрос больше, если Constraint Layout предлагает что-то более простое. –

+0

Да, вы правы, это, по-видимому, рекомендуется, я узнал его из программы Android Nanodegree. – SanthoshN