对于每个n个图像视图(如图库时间轴),在GridView上显示textview

时间:2015-08-06 14:59:12

标签: android gridview android-listview

我正在尝试构建一个布局,如图所示,其中Date(TextView)显示在GridView中的图像上方,TextView多次出现在视图中。我对如何实现它很困惑。我尝试将TextView放在列表项中,但在这种情况下,TextView对每一行都重复。任何人都可以建议如何使用此参考图像。

main.xml中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/lvTimeline"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>
</LinearLayout>

list_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/rlText">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="14sp"
        android:text="28 Feb"
        android:layout_marginLeft="16dp"
        android:layout_alignParentLeft="true"
        android:id="@+id/tvDate"/>

</RelativeLayout>

<GridView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/gvTest"
    android:numColumns="3"
    android:verticalSpacing="3dp">

</GridView>

gridview_item.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">



<ImageView
    android:layout_width="116dp"
    android:layout_height="116dp"
    android:scaleType="fitXY"
    android:id="@+id/ivTimeline"
    android:src="@android:drawable/sym_def_app_icon"/>

列表适配器:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View view = convertView;
    ViewHolder holder;

    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) parent.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.list_item, parent, false);
        holder = new ViewHolder();
        holder.tvDate = (TextView) view.findViewById(R.id.tvDate);
        holder.gvTimeline = (GridView) convertView
                .findViewById(R.id.gvTest);


        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    holder.gvTimeline.setAdapter(new GridAdapter(imagesList));


    return view;

}



public static class ViewHolder {
    TextView tvDate;
    GridView gvTimeline;
}

GridView适配器:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View view = convertView;
    ViewHolder holder;

    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) parent.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.gridview_item, parent, false);
        holder = new ViewHolder();
        holder.ivImage = (ImageView) view.findViewById(R.id.ivTimeline);
         view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    holder.ivImage.setImageResource(getItem(position));


    return view;

}



public static class ViewHolder {
   ImageView ivImage;
}

enter image description here

我现在得到的图片: enter image description here

0 个答案:

没有答案