像在Play商店应用中一样创建自定义列表视图布局

Nii*_*yea 2 xml android android-layout

播放商店图片

大家好,我想创建一个像这样的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>
Run Code Online (Sandbox Code Playgroud)

但它甚至没有我想要的东西.我只是不确定我会怎么做.任何帮助都会很棒.

dha*_*rms 5

希望这将为您提供一个良好的起点,以满足您的需求.

<?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>
Run Code Online (Sandbox Code Playgroud)