Grid view like Windows 8 or Google Play

2019-05-27 09:40发布

问题:

I'm looking for the source code, or an example, of a gridview. I know that with eclipse i can do something really simple: many squares next to each other.

But i want to have something strange and particular like this example:

Click here

Someone can help me?

回答1:

You can use StaggerdGridview from Here Github

It Looks Like This



回答2:

You can do it through layout nesting. It's basically just like doing your html pages. For example:

<?xml version="1.0" encoding="utf-8"?>

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

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="226dp"
            android:background="@color/dark_shadow">
    </LinearLayout>

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

        <LinearLayout
                android:orientation="vertical"
                android:layout_width="180dp"
                android:layout_height="fill_parent"
                android:background="@color/holo_bright_blue">
        </LinearLayout>

        <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                >

            <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="154dp"
                    android:background="@color/me_blue">
            </LinearLayout>

            <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="106dp"
                        android:layout_height="fill_parent"
                        android:background="@color/dark_shadow">
                </LinearLayout>

                <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:background="@color/light_gray">
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>
</LinearLayout>

Also make use of the layout weight and weight sum of the parent container is you need to add other views inside those layouts. Hope this will give you some hints on what you're trying to achieve.