I'm trying to develop one new project. My client wants me to design like current GooglePlay design (block design per attach). That's why I'm confused whether <android.support.v7.widget.GridLayout>
will be useful or not for implement such block design featured. If not, please let me know how to do it?
Asked
Active
Viewed 7,694 times
3

PPShein
- 13,309
- 42
- 142
- 227
1 Answers
6
You might want to take a look at http://developer.android.com/design/building-blocks/grid-lists.html. Not exactly sure what you are trying to do, but I hope this helps. It uses GridView instead of GridLayout. A good post about that can be found GridView VS GridLayout in Android Apps
Edit: Here is my example
Note: Most of this is taken from http://developer.android.com/guide/topics/ui/layout/gridview.html. The ImageAdapter used in GridViewExample is taken directly from there as are the pictures used.
Here is my layout
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textSize="50sp"
android:gravity="center_horizontal"
android:text="Page Title" />
<!-- Insert some sort of scrolling if desired -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:textColor="@android:color/white"
android:textSize="25sp"
android:gravity="center_horizontal"
android:text="Grid 1 Title" />
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:columnWidth="50dp"
android:numColumns="auto_fit"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:stretchMode="columnWidth"
android:gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:textColor="@android:color/white"
android:textSize="25sp"
android:gravity="center_horizontal"
android:text="Grid 2 Title" />
<GridView
android:id="@+id/gridView2"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:columnWidth="50dp"
android:numColumns="auto_fit"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:stretchMode="columnWidth"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
Here is my Main Activity:
package com.example.gridviewdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;
public class GridViewExample extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview_example);
GridView gridView1 = (GridView) findViewById(R.id.gridView1);
gridView1.setAdapter(new ImageAdapter(this));
gridView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(GridViewExample.this, "1: " + position, Toast.LENGTH_SHORT).show();
}
});
GridView gridView2 = (GridView)findViewById(R.id.gridView2);
gridView2.setAdapter(new ImageAdapter(this));
gridView2.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
Toast.makeText(GridViewExample.this, "2: " + position, Toast.LENGTH_SHORT).show();
}
});
}
}
Produces:
It looks like the layout is a little off on a tablet, but with some work I am sure that can be fixed
-
I've already looked it up but has not got any idea to implement it yet. – PPShein Jul 15 '13 at 03:54
-
If your goal is to get it to look like the screen shots, wouldn't it be possible to use a combination of GridView's and TextView's inside a LinearLayout? – kalelien Jul 15 '13 at 04:01
-
any example can you more provide? By the way, 1 vote up. – PPShein Jul 15 '13 at 04:02
-
I will give it a shot, but may take a little while - and thanks – kalelien Jul 15 '13 at 04:08
-
Just posted the edit. I think this is what you are looking for. You can scroll vertically within the GridView and select each picture individually. – kalelien Jul 15 '13 at 05:12