【发布时间】:2016-11-09 20:19:58
【问题描述】:
我正在尝试为我的 ListView 构建此自定义行。通过 Photoshop 的魔力,这就是我想要实现的目标:
但是当我运行我的列表视图时,它是这样出来的:
谁能帮我弄清楚我在视图中做错了什么?
这是我的 row.xml
<?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="match_parent"
android:orientation="horizontal"
android:padding="5dp">
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true">
<ImageView
android:id="@+id/list_image"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_alignParentRight="true"
android:background="@color/COLOR_GREY" />
</LinearLayout>
<!-- Item Name -->
<TextView
android:id="@+id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="Item Name"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
<!-- progress count -->
<TextView
android:id="@+id/txtProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/thumbnail"
android:layout_alignLeft="@+id/thumbnail"
android:text="Item Name"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
<!-- Retry button -->
<Button
android:id="@+id/btnRetry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/txtItemName"
android:layout_toRightOf="@id/txtItemName"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:text="Retry" />
<!-- Delete button -->
<Button
android:id="@+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/btnRetry"
android:layout_toRightOf="@id/btnRetry"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:text="Delete" />
<!-- ProgressBar -->
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_below="@id/txtItemName"
android:layout_alignLeft="@id/txtItemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBarItem" />
</RelativeLayout>
【问题讨论】:
-
首先,
RelativeLayout不使用“方向”,LinearLayout` 使用,然后,当您引用视图时,您在访问其 ID 时不使用+符号,它仅用于创建新 ID。所以首先我会解决这个问题。并且您正在使用 ImageView 布局的全宽使其他元素出现在屏幕外
标签: java android listview material-design