recommend
This commit is contained in:
@@ -8,10 +8,12 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.R;
|
||||
import com.example.ninefourone.nutritionmaster.adapter.RecommendAdapter;
|
||||
import com.example.ninefourone.nutritionmaster.base.BaseFragment;
|
||||
import com.example.ninefourone.nutritionmaster.bean.RecommendFood;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -30,6 +32,8 @@ public class RecommendFragment extends BaseFragment {
|
||||
|
||||
private RecommendAdapter adapter;
|
||||
private ArrayList<RecommendFood> datas = new ArrayList<>();
|
||||
private GridLayoutManager manager;
|
||||
private int[] indexs = new int[]{0, 1, 1, 2};
|
||||
|
||||
@Override
|
||||
public int getLayoutResId() {
|
||||
@@ -67,8 +71,24 @@ public class RecommendFragment extends BaseFragment {
|
||||
@Override
|
||||
protected void initRecyclerView() {
|
||||
adapter = new RecommendAdapter(datas);
|
||||
adapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
|
||||
adapter.isFirstOnly(false);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
|
||||
recyclerView.setNestedScrollingEnabled(false);
|
||||
manager = new GridLayoutManager(getContext(), 2);
|
||||
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
||||
@Override
|
||||
public int getSpanSize(int position) {
|
||||
if (adapter.getItemViewType(position) == RecommendFood.TYPE_BIG ||
|
||||
adapter.getItemViewType(position) == RecommendFood.TYPE_DETAIL) {
|
||||
// Logger.d(manager.getSpanCount());
|
||||
return manager.getSpanCount();
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
recyclerView.setLayoutManager(manager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +98,7 @@ public class RecommendFragment extends BaseFragment {
|
||||
protected void loadData() {
|
||||
super.loadData();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", i % 3);
|
||||
RecommendFood recommendFood = new RecommendFood(1, "烧肉", "好吃", indexs[i % 4]);
|
||||
datas.add(recommendFood);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,13 @@
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<FrameLayout
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:textSize="20sp"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="红烧肉" />
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<android.support.v7.widget.CardView 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"
|
||||
android:layout_width="170dp"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="@dimen/recommend_item_default_hight"
|
||||
android:layout_margin="@dimen/recommend_margin"
|
||||
android:layout_weight="1"
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
<string-array name="sections">
|
||||
<item>一周定制</item>
|
||||
<item>今日信息</item>
|
||||
<item>page3</item>
|
||||
<item>推荐菜谱</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
<dimen name="icon_size">20dp</dimen>
|
||||
|
||||
<dimen name="recommend_item_default_hight">130dp</dimen>
|
||||
<dimen name="recommend_item_big_height">250dp</dimen>
|
||||
<dimen name="recommend_margin">10dp</dimen>
|
||||
<dimen name="recommend_item_default_hight">100dp</dimen>
|
||||
<dimen name="recommend_item_big_height">180dp</dimen>
|
||||
<dimen name="recommend_margin">5dp</dimen>
|
||||
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user