2016-11-29 2 views
0

Я боролся в течение нескольких дней, пытаясь создать пользовательский макет в Android, разделенный на 3 части, контейнер для голосования «vote», который отображает количество людей, которые проголосовали за сообщение, контейнер текстовых сообщений, который будет содержать текст и автора сообщения, и контейнер кнопки, который будет использоваться для голосования вверх или вниз по сообщению.Android: Container XML Layout вес упаковки и высота заполнения

До сих пор у меня есть этот код

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/containerInner" 
    > 

    <!-- # VOTES CONTAINER --> 
    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/containerVotes" 
     android:layout_centerVertical="true" 
    > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:id="@+id/votesPost" 
      android:textStyle="bold" 
      android:textSize="16sp" 
     /> 
    </RelativeLayout> 

    <!-- MESSAGE CONTAINER --> 
    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/containerText" 
     android:layout_marginLeft="4dp" 
     android:layout_marginTop="4dp" 
     android:layout_toRightOf="@+id/containerVotes" 
     android:background="@color/gray" 
     > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#000000" 
      android:id="@+id/titleGlobus" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/AutorGlobus" 
      android:textColor="#000000" 
      android:textSize="12sp" 
      android:textStyle="italic" 
      android:maxWidth="180dp" 
      android:layout_weight="0.1" 
      android:layout_below="@+id/titleGlobus" 
      /> 

    </RelativeLayout> 

    <!-- VOTE UP/DOWN CONTAINER --> 

    <RelativeLayout 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:id="@+id/containerButtons" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/containerText" 
     android:layout_toEndOf="@+id/containerText" 
     > 

     <RelativeLayout 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:id="@+id/containerButtonUp" 
      > 

      <at.markushi.ui.CircleButton 
       android:layout_width="32dip" 
       android:layout_height="32dip" 
       android:src="@mipmap/ic_arrow_drop_up_black_24dp" 
       app:cb_color="@color/white" 
       app:cb_pressedRingWidth="8dip" 
       android:id="@+id/upvote_button" 
       /> 

     </RelativeLayout> 

     <RelativeLayout 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:id="@+id/containerButtonDown" 
      android:layout_below="@+id/containerButtonUp" 
      > 

      <at.markushi.ui.CircleButton 
       android:layout_width="32dip" 
       android:layout_height="32dip" 
       app:cb_color="@color/white" 
       app:cb_pressedRingWidth="8dip" 
       android:src="@mipmap/ic_arrow_drop_down_black_24dp" 
       android:id="@+id/downvote_button" 
       /> 

     </RelativeLayout> 

    </RelativeLayout> 

Макет Я получаю в телефон с помощью приведенного выше кода заключается в следующем:

Pre

И я хочу, чтобы достичь это:

Post

Итак, есть две основные вещи, которые мне нужны, чтобы достичь здесь:

  • сделать RelativeLayout containerText заполнить всю высоту его вышестоящего контейнера.

  • Выйдите из имени автора справа от контейнера, но выровняйте его только в конце «сообщения» TextView.

Я пытался решить проблему исправить изменяющуюся высоту containerText контейнера в fill_parent без успеха, меняя весь путь до главного контейнера всех свойств высоты к fill_parent.

Если я попытаюсь выровнять имя автора справа, используя alignParentRight = true, RelativeLayout затем занимает все пространство экрана, выталкивая контейнер кнопок. Я также пытался изменить способ позиционирования различных макетов уважать других, меняя toLeftOf или toRightTo, с ужасными результатами.

Любая помощь будет высоко оценена, поскольку я застрял в этой проблеме.

Cheers!

ответ

0

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

<!-- MESSAGE CONTAINER --> 
    <RelativeLayout 
     android:layout_width="wrap_content" 

     <!-- Set this height to match_parent --> 
     android:layout_height="match_parent" 

     android:id="@+id/containerText" 
     android:layout_marginLeft="4dp" 
     android:layout_marginTop="4dp" 
     android:layout_toRightOf="@+id/containerVotes" 
     android:background="@color/gray" 
     > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#000000" 
      android:id="@+id/titleGlobus" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/AutorGlobus" 
      android:textColor="#000000" 
      android:textSize="12sp" 
      android:textStyle="italic" 
      android:maxWidth="180dp" 
      android:layout_weight="0.1" 

      <!-- Removed below tag and added alignParentBottom and alignParentRight --> 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      /> 

    </RelativeLayout> 
+0

Установка 'андроида: layout_alignParentRight = "истинный"' делает TextView, чтобы заполнить всю ширину -> дает этот вывод: http://imgur.com/a/a5EkB Извлечение layout_below приводит к тому, что оно отображается справа от сообщения, как если бы макет не мог расти вертикально. – PayToPwn

+0

Вы добавили alignParentBottom? Он должен придерживаться его в нижней части контейнера –

+0

Да, я изменил match_parent в layout_height и добавил alignParentBottom и alignParentRight, но я получаю изображение, которое я разместил в последнем комментарии. – PayToPwn

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

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