GridView控件 - 图像,文本和项目单击

GridView控件 - 图像,文本和项目单击

问题描述:

我的朋友 我是一个新的Android和我想做一个例子(代码)喜欢的图片 GridView控件 - 图像,文本和项目单击 感谢所有enter image description hereGridView控件 - 图像,文本和项目单击

+1

你应该开始寻找在线教程...问题太广泛,因为SO – Selvin

+1

去Fiverr并付钱给你,让它为你 – Forbs

+0

不要去fiverr,让别人为你做,他们会做它以最简单快捷的方式,而不会考虑未来的问题。 –

你正在寻找RecyclerView。创建布局并添加recyclerView它然后创建了recyclerview下面的行另一个布局文件:

<RelativeLayout 
       android:id="@+id/relativeLayout2" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <android.support.v7.widget.RecyclerView 
        android:id="@+id/recyclerView" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"/> 

</RelativeLayout> 

创建另一个布局row_layout.xml

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 


    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:srcCompat="@mipmap/ic_launcher" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TextView"/> 

</RelativeLayout> 

然后在你的MainActivity,加上下面几行代码:

RecyclerView recyclerView = findViewById(R.id.recyclerView); 
recyclerView.setHasFixedSize(true); 
RecyclerView.LayoutManager gridLayoutManager = new GridLayoutManager(this, 2, false); 
recyclerView.setLayoutManager(gridLayoutManager); 

在此之后,根据您的具体需要进行recyclerView可以用快速谷歌搜索发现创建一个适配器。只需在适配器的onCreateViewHolder中重新启动row_layout即可。创建适配器后,只需将其设置为您的recyclerView。

recyclerView.setAdapter(your_custom_adapter); 

这只是你应该做的事情的要点。它会让你开始正确的方向。其余的只是一个搜索。