android - 创建自定义 ListView 布局,就像在 Play 商店应用中一样

标签 android xml android-layout

Play store image

大家好,我想创建一个像这样的 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/

相关文章:

Android - 在同一应用程序中包含多个广告提供商。可能的?

xml - 如何在项目而不是工作区中保存 XML 格式设置?

python - 如何将xml文件保存到磁盘?

java.lang.ClassCastException : org. ksoap2.serialization.SoapPrimitive 无法转换为 org.ksoap2.serialization.SoapObject

android - 如何在另一个图像之上获得半透明图像以在 android 中保存文本(提供的屏幕截图)

java - ViewPager中Fragment的查看更新回调

android - 移动应用程序 : how to show the OTP my app sends in a popup without leaving my app?

android - MediaPlayer getCurrentPosition() 问题

c# - 在 C# 中,我应该如何反序列化完整的 SOAP XML 响应

Android 样式 : Difference between 'style="@android:style/XYZ "' and ' style ="?android:attr/XYZ"'?