【发布时间】:2016-10-28 01:19:55
【问题描述】:
我正在开发一个 android 应用程序,在该应用程序中我使用来自我的网络服务器的项目填充我的回收视图。
问题, 我不太清楚我的 recyclerview 出了什么问题,每个“项目”似乎占据了整个屏幕,我查看了其他 XML 格式,它们似乎与我的相同。然而我有很大的余地。 参考图片
XML
自定义行xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cv"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/person_photo"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="16dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/person_name"
android:layout_toRightOf="@+id/person_photo"
android:layout_alignParentTop="true"
android:textSize="30sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/person_age"
android:layout_toRightOf="@+id/person_photo"
android:layout_below="@+id/person_name"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
回收器碎片
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/cointainerDrawerID"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/drawrList"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
在图片中,您会看到两个项目,但一个位于另一个下方。它位于完全不同的页面上。
【问题讨论】:
-
你必须给
CardView一个固定的高度
标签: android xml android-layout