大家好,我想创建一个像这样的 ListView 项/行。我了解如何创建自定义 ListView 和适配器,但让每个列表项/行有点“独立”,我一直无法弄清楚。
如何创建这样的东西?
编辑:根据 dcharms 的建议,我尝试了以下操作:
<?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="wrap_content"
android:background="@android:color/darker_gray" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@android:color/white"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:contentDescription="@string/none"
android:src="@drawable/logo" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:text="@string/none" />
</LinearLayout>
</RelativeLayout>
但这离我想要的还差得很远。我只是不太确定我会怎么做。任何帮助都会很棒。
最佳答案
希望这能为您寻找所需的内容提供一个良好的起点。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#dddddd" >
<View
android:id="@+id/shadowView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#cccccc" />
<RelativeLayout
android:id="@+id/innerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:background="#ffffff" >
<ImageView
android:id="@+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:src="@drawable/logo"
android:contentDescription="@string/none"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/icon"
android:text="@string/none" />
</RelativeLayout>
</RelativeLayout>
关于android - 创建自定义 ListView 布局,就像在 Play 商店应用中一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23248022/