GooglePlayっぽい感じ

![device-2016-03-04-203932.png](https://qiita-image-store.s3.amazonaws.com/0/99731/01856483-4e44-dde0-4e25-96935d5bfd0a.png)

```python:build.gradle
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile "com.android.support:cardview-v7:+"
    compile 'com.android.support:design:23.1.1'
}
```

```xml:activity_main.xml
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/button_material_light">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:titleTextColor="@android:color/white"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.AppBarLayout>


    <android.support.v7.widget.RecyclerView
            android:id="@+id/card_list"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        app:layout_behavior=".ScrollAwareFABBehavior"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchorGravity="bottom|right|end"
        app:layout_anchor="@id/card_list"
        android:layout_gravity="bottom|right"
        android:src="@android:drawable/ic_dialog_email" />


</android.support.design.widget.CoordinatorLayout>

```


```java:MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    final String rating_str = "4.1★";
    final int app_list_count = 50;
    AppInfoAdapter adapter;
    List<AppInfo> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Toolbar初期化
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);

        RecyclerView recycle = (RecyclerView) findViewById(R.id.card_list);
        recycle.setHasFixedSize(true);
        recycle.setLayoutManager(manager);

        list = new ArrayList<>();
        for (int i=0; i <= app_list_count; i++) {
            AppInfo app = new AppInfo();
            app.name = i + ".アプリ";
            app.rating = rating_str;
            app.developer_name =  "デベロッパー " + i;
            list.add(app);
        }
        adapter = new AppInfoAdapter(list);
        recycle.setAdapter(adapter);
        /*
        ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(
               0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

            @Override
            public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
                return makeFlag(ItemTouchHelper.ACTION_STATE_IDLE, ItemTouchHelper.RIGHT) | makeFlag(ItemTouchHelper.ACTION_STATE_SWIPE, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) |
                        makeFlag(ItemTouchHelper.ACTION_STATE_DRAG, ItemTouchHelper.DOWN | ItemTouchHelper.UP);
            }



            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                final int fromPos = viewHolder.getAdapterPosition();
                final int toPos = target.getAdapterPosition();
                adapter.notifyItemMoved(fromPos, toPos);
                return true;
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                // callback for swipe to dismiss, removing item from data and adapter

                list.remove(viewHolder.getAdapterPosition());
                adapter.notifyItemRemoved(viewHolder.getAdapterPosition());
            }
        });
        swipeToDismissTouchHelper.attachToRecyclerView(recycle);
*/


    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    public static class AppInfo {
        protected String developer_name;//デベロッパーメイン
        protected String name; //アプリの名前
        protected String rating; //レーティング
    }
    public static class AppInfoAdapter extends RecyclerView.Adapter<AppInfoViewHolder> {

        private List<AppInfo> AppInfo_list;

        public AppInfoAdapter(List<AppInfo> AppInfo_list) {
            this.AppInfo_list = AppInfo_list;
        }
        @Override
        public int getItemCount() {
            return AppInfo_list.size();
        }
        @Override
        public void onBindViewHolder(AppInfoViewHolder ViewHolder, int i) {
            AppInfo app = AppInfo_list.get(i);
            ViewHolder.developer_name.setText(app.developer_name);
            ViewHolder.name.setText(app.name);
            ViewHolder.rating.setText(app.rating);
            ViewHolder.icon.setImageResource(R.mipmap.ic_launcher);
        }
        @Override
        public AppInfoViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            View itemView = LayoutInflater.
                    from(viewGroup.getContext()).
                    inflate(R.layout.card_layout, viewGroup, false);
            return new AppInfoViewHolder(itemView);
        }
    }
    public static class AppInfoViewHolder extends RecyclerView.ViewHolder {
        protected TextView name;
        protected ImageView icon;
        protected TextView rating;
        protected TextView developer_name;
        public AppInfoViewHolder(View v) {
            super(v);
            developer_name = (TextView)  v.findViewById(R.id.developer_name);
            name = (TextView) v.findViewById(R.id.app_name);
            icon = (ImageView) v.findViewById(R.id.icon);
            rating = (TextView) v.findViewById(R.id.rating);
        }
    }
}

```

```xml:res/layout/card_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    android:layout_marginLeft="3dp"
    android:layout_marginRight="3dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <ImageView
            android:id="@+id/icon"
            android:background="@drawable/kakumaru"
            android:layout_alignParentLeft="true"
            android:layout_width="80dp"
            android:layout_height="80dp" />

        <TextView
            android:id="@+id/app_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@id/icon"
            android:textColor="@android:color/black"
            android:textSize="15dp"/>


        <TextView
            android:id="@+id/developer_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="2dp"
            android:layout_toRightOf="@id/icon"
            android:layout_below="@id/app_name"/>

        <TextView
            android:id="@+id/rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="2dp"
            android:textSize="13dp"
            android:textColor="#000"
            android:layout_toRightOf="@id/icon"
            android:layout_below="@id/developer_name"/>

        <TextView
            android:text="︙"
            android:singleLine="true"
            android:ellipsize="end"
            android:rotation="90"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:textSize="23dp"
            android:textStyle="bold"
            android:padding="4dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:text="無料"
            android:textColor="#689e38"
            android:layout_alignParentBottom="true"
            android:textSize="13dp"
            android:layout_alignParentRight="true"
            android:padding="11dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </RelativeLayout>
</android.support.v7.widget.CardView>

```

```xml:res/menu/menu_main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never" />
</menu>

```

```xml:res/drawable/kakumaru.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners
                android:topRightRadius="5dp"
                android:bottomRightRadius="5dp"
                android:bottomLeftRadius="5dp"
                android:topLeftRadius="5dp"
                android:color="#626262"
                />

            <stroke
                android:width="0.1dp"
                />


        </shape>
    </item>
</selector>

```

```java:ScrollAwareFABBehavior.java
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;

public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {
    public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
        super();
    }

    @Override
    public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child,
                                       final View directTargetChild, final View target, final int nestedScrollAxes) {
        // Ensure we react to vertical scrolling
        return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
                || super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
    }

    @Override
    public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child,
                               final View target, final int dxConsumed, final int dyConsumed,
                               final int dxUnconsumed, final int dyUnconsumed) {
        super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
        if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
            // User scrolled down and the FAB is currently visible -> hide the FAB
            child.hide();
        } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
            // User scrolled up and the FAB is currently not visible -> show the FAB
            child.show();
        }
    }
}
```

```xml:style.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item><!-- Toolbar背景 -->
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@android:color/white</item>
    </style>
</resources>
```