我有一个listview项目的布局,但它显示不正确(书籍描述超过了上次更新日期)。你能帮我解决一下吗?
如果我设置
android:layout_above="@+id/lastUpdatedDt"
到bookDescr项目,整个文本消失......
编辑:我已根据评论
更新了样本<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>
答案 0 :(得分: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"
lastUpdatedDt
设置TextView
,这样lastUpdatedDt
将始终位于父级的底部,低于bookDescription
TextView
兄弟。