2014-04-25 2 views
0

У меня есть макет элемента списка, и он отображается неправильно (книга descr проходит через последнюю дату обновления). Не могли бы вы помочь мне исправить?Корректное использование RelativeLayout

Если установить

android:layout_above="@+id/lastUpdatedDt" 

к элементу bookDescr весь текст исчезает ...

EDIT: Я обновил образец в соответствии с комментариями

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:descendantFocusability="blocksDescendants" 
    android:layout_margin="10dp" 
    android:background="@drawable/big_card_details" 
    android:clickable="true" 
    android:focusable="false"> 

<CheckBox 
    android:id="@+id/icon" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    style="?android:attr/starStyle" 
    android:layout_marginTop="10dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginLeft="10dp" /> 

    <TextView 
     android:id="@+id/bookTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Book title" 
     android:textSize="16sp" 
     android:layout_alignBaseline="@id/icon" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@id/icon" /> 

    <TextView 
     android:id="@+id/bookSize" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:text="470k" 
     android:layout_alignBaseline="@id/icon" 
     android:textSize="16sp" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="10dp" /> 

<TextView 
    android:id="@+id/lastUpdatedDt" 
    android:layout_width="match_parent" 
    android:layout_height="26dip" 
    android:singleLine="true" 
    android:text="Updated 27.04.2014 17.10" 
    android:textSize="12sp" 

    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentBottom="true" 
    android:layout_alignLeft="@id/icon" /> 
<TextView 
     android:id="@+id/bookDescription" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:singleLine="false" 
    android:textSize="10sp" 
    android:text="here should be long description" 
    android:layout_alignEnd="@id/bookSize" 
    android:layout_below="@+id/bookTitle" 
    android:layout_marginTop="20dp" 
    android:layout_alignLeft="@+id/icon" /> 



    <!-- this is the button that will trigger sliding of the expandable view --> 

    <ImageButton 
     android:id="@+id/expand_details_button" 
     android:src="@drawable/slide_button_details" 
     android:layout_alignTop="@id/lastUpdatedDt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:layout_alignBaseline="@id/lastUpdatedDt" 
     android:layout_alignParentBottom="true" 
     android:layout_alignRight="@id/bookSize" 
     android:layout_alignEnd="@id/bookSize" /> 

    </RelativeLayout> 

<!-- this is the expandable view that is initially hidden and will slide out when the more button is pressed --> 
<LinearLayout 
    android:id="@+id/details_expandable" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:baselineAligned="false" 
    android:orientation="horizontal" 
    > 
    <!-- put whatever you want in the expandable view --> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_weight="0.3" 
     android:drawableTop="@drawable/ic_action_read" 
     android:text="@string/ReadBook" 
     style="@style/SlideButtonTheme" /> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_weight="0.3" 
     android:drawableTop="@drawable/ic_action_open_browser" 
     style="@style/SlideButtonTheme" 
     android:text="@string/OpenInBrowser" /> 

</LinearLayout> 
</LinearLayout> 
+3

Вопросы, которые я вижу до сих пор: ** 1 ** - У вас слишком много макетов. ** 2 ** - xmlns повторяется (WRONG !!). ** 3 ** - Вместо '@ id' вы используете' @ + id', когда REFERRING для идентификаторов ('@ + id' следует использовать только для создания новых идентификаторов). ** 4 ** - 'fill_parent' устарел с API 8. Поскольку API 8, вы должны использовать' match_parent' –

+0

1. У меня есть только 3 макета (минимум требуется для пользовательского вида https://github.com/tjerkw/ Android-SlideExpandableListView 2. Thx 3. Не знаю, thx 4. Мой min sdk равен 8, поэтому я изменю его на match_parent, thx –

+0

1 - У вас есть 4 макета, вы можете многопрофилировать (возможно, сократить до 1 или двух или, в худшем случае, 3) - я не буду изучать этот вопрос в глубине. Имейте в виду, что чем меньше макетов (и меньше элементов управления) вы используете, тем лучше вы получите, и, следовательно, лучше –

ответ

0

Надежда ваша известно, что вид ребенка в RelativeLayout необходимо разместить below/above any of the sibling views или aligned from the parent.

Проблема здесь состоит в том, что lastUpdatedDt является aligned to parent bottom, так как высота родительского RelativeLayout устанавливается на wrap_content высоте будет решаться на основе мнений ребенка, так что lastUpdatedDt находится в нижней части зависит от родительской высоты, которые перекрывают друг друга вид сестры.

FIX: Просто установите android:layout_below="@+id/bookDescription" для lastUpdatedDtTextView, так что lastUpdatedDt всегда будет размещен снизу родителя и ниже bookDescriptionTextView собрата.

+0

спасибо за объяснение и исправление! –

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