如何在 GridView 中显示带有文本和关闭按钮(如 Gmail)的照片?
感谢
通过在您的自定义布局中设置它来尝试使用以下GridView
布局。
<?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="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/llcolor"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/gridimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:background="@drawable/puppy"
android:scaleType="fitXY" />
<LinearLayout
android:id="@+id/llv1234"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/black_bg"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv_profilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="Name"
android:textColor="#ffffff" />
<LinearLayout
android:id="@+id/linh"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:gravity="right|center" >
<LinearLayout
android:id="@+id/gv_llike_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp" >
<ImageView
android:id="@+id/gv_ivlike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="5dp"
android:src="@drawable/delete" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
输出:
您应该使用 RelativeLayout 作为 GridViewItem 的父级,并在那里添加一个 ImageView 和一个具有水平方向并包含一个 TextView 和一个 imageView 的 LinearLayout 或 ImageButoon.LinearLayout 应该将 AlignParentBottom 设置为 true。
将此框架布局用于您的网格项目。创建一个扩展基本适配器的自定义适配器类。
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip" >
<ImageView
android:id="@+id/imgWallpaper"
android:layout_width="fill_parent"
android:layout_height="250dip"
android:contentDescription="@string/app_name"
android:scaleType="fitXY" >
</ImageView>
<TextView
android:id="@+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/transparent_layer"
android:contentDescription="@string/app_name"
android:gravity="center|right"
android:paddingRight="10dip"
android:text="Rethinavel Pillai"
android:textColor="#FFFFFF"
android:textIsSelectable="false" />
<TextView
android:id="@+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/transparent_layer"
android:contentDescription="@string/app_name"
android:gravity="center|left"
android:paddingRight="10dip"
android:text="Rethinavel Pillai"
android:textColor="#FFFFFF"
android:textIsSelectable="false" />
</FrameLayout>
希望对您有帮助,否则请告诉我