如何在单击的单元格下方显示textview。?

时间:2017-04-24 17:50:00

标签: android

This is the reference image link

我从Flickr获取图像并在gridview中显示它们。 问题是textview会显示在gridview的顶部。

到目前为止我做了什么:

      mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> gridView, View view, int pos,
                                long id) {

            GalleryItem item = mItems.get(pos);
            LinearLayout layout = new LinearLayout(getContext());
            layout.setLayoutParams(new GridView.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
            layout.setOrientation(LinearLayout.HORIZONTAL);
            TextView textview = new TextView(getContext());
            textview.setLayoutParams(new LinearLayout.LayoutParams(
                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
            textview.setText("Get the Position " + pos);
            textview.setTextColor(Color.RED);

            layout.addView(textview);
        }
    });

1 个答案:

答案 0 :(得分:0)

您可以使用带有GridLayout Manager的回收器视图,并在自定义布局中添加textView以下的textView,并根据单击的视图显示/隐藏。

找到以下参考: http://www.androidhive.info/2016/05/android-working-with-card-view-and-recycler-view/