将网格标题添加到网格卡android

时间:2016-03-04 06:40:46

标签: android material-design android-gridview android-cardview

我正在使用//table[@class='detailTable'][1]//td[@class="detailTitle" and contains(./h3, 'Statement Date')]/following-sibling::td[1]/p[1]/text()网格中的图像,我想在图像中添加网格标题,如图所示。在互联网上搜索但发现简单添加文本而不是这种类型的页脚文本。

https://jsfiddle.net/xv2vph6c/9/

2 个答案:

答案 0 :(得分:1)

你需要像这样创建一张卡

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ff0000">
    <ImageView
        android:id="@+id/overlayImage"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="@drawable/education"
        />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_gravity="bottom"
        android:background="#70000000">
        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/icon"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:src="@android:drawable/ic_dialog_info"
            />
        <TextView
            android:id="@+id/tvNewsContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toLeftOf="@+id/icon"
            android:ellipsize="end"
            android:maxLines="3"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:text="Big CNG scam behind odd-even plan, says woman who threw ink at Kejriwal,plan, says woman who threw ink at Kejriwal"
            android:textColor="@color/white"
            android:textSize="@dimen/feed_name_size"
            android:textStyle="bold"
            android:gravity="center_vertical"

            />
    </RelativeLayout>

</FrameLayout>

你的卡片看起来像这样

enter image description here

答案 1 :(得分:0)

将适配器设置为网格视图,如下面的代码所示

公共类FirstActivityAdapter扩展了BaseAdapter {

String[] result;
Context context;
int[] imageId;
Intent i;

private static LayoutInflater inflater = null;

public FirstActivityAdapter(Context mainActivity, String[] prgNameList, int[] prgImages) {

    result = prgNameList;
    context = mainActivity;
    imageId = prgImages;
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}
@Override
public int getCount() {
    return result.length;
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}

public class Holder {

    ImageView imageView;
    TextView textView;

}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    Holder holder = new Holder();
    View rowView;
    rowView = inflater.inflate(R.layout.main_category_list_item, null);
    holder.imageView = (ImageView) rowView.findViewById(R.id.image_view_for_grid_view);
    holder.textView = (TextView) rowView.findViewById(R.id.text_view_for_image);
    holder.textView.setText(result[position]);
    holder.imageView.setImageResource(imageId[position]);
    rowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (position) {
                case 0:
                  i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;
                case 1:
                    i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;
                case 2:
                    i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;
                case 4:
                    i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;
                case 5:
                    i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;
                case 6:
                    i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;
                case 7:
                    i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;
                case 8:
                    i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;
                case 9:
                    i = new Intent(context,SecondActivity.class);
                    context.startActivity(i);
                    break;


            }

        }


    });

    return rowView;