grid layout manger fix
This commit is contained in:
BIN
.idea/caches/gradle_models.ser
generated
BIN
.idea/caches/gradle_models.ser
generated
Binary file not shown.
29
.idea/codeStyles/Project.xml
generated
29
.idea/codeStyles/Project.xml
generated
@@ -1,29 +0,0 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<code_scheme name="Project" version="173">
|
|
||||||
<Objective-C-extensions>
|
|
||||||
<file>
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
|
||||||
</file>
|
|
||||||
<class>
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
|
||||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
|
||||||
</class>
|
|
||||||
<extensions>
|
|
||||||
<pair source="cpp" header="h" fileNamingConvention="NONE" />
|
|
||||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
|
||||||
</extensions>
|
|
||||||
</Objective-C-extensions>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
|
||||||
4
.idea/encodings.xml
generated
Normal file
4
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||||
|
</project>
|
||||||
@@ -85,7 +85,7 @@ public class CampaignProductListActivity extends BaseActivity {
|
|||||||
startActivityForResult(productPropertiesIntent, REQUEST_CODE_CAMPAIGN_PRODUCT_PROPERTIES);
|
startActivityForResult(productPropertiesIntent, REQUEST_CODE_CAMPAIGN_PRODUCT_PROPERTIES);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
campaignProductRecyclerView.addItemDecoration(new GridSpacesItemDecoration(DisplayHelper.dpToPx(12)));
|
campaignProductRecyclerView.addItemDecoration(new GridSpacesItemDecoration(2, 16, true));
|
||||||
campaignProductRecyclerView.setAdapter(menuProductRecyclerAdapter);
|
campaignProductRecyclerView.setAdapter(menuProductRecyclerAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class MenuFragment extends BaseFragment {
|
|||||||
//showBottomsheetDialog(menuProductList.get(position));
|
//showBottomsheetDialog(menuProductList.get(position));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menuProductRecyclerView.addItemDecoration(new GridSpacesItemDecoration(DisplayHelper.dpToPx(12)));
|
menuProductRecyclerView.addItemDecoration(new GridSpacesItemDecoration(2, 16, true));
|
||||||
menuProductRecyclerView.setAdapter(menuProductRecyclerAdapter);
|
menuProductRecyclerView.setAdapter(menuProductRecyclerAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class ProductFragment extends BaseFragment {
|
|||||||
//showBottomsheetDialog(productList.get(position));
|
//showBottomsheetDialog(productList.get(position));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
customProductRecyclerView.addItemDecoration(new GridSpacesItemDecoration(DisplayHelper.dpToPx(12)));
|
customProductRecyclerView.addItemDecoration(new GridSpacesItemDecoration(2, 16, true));
|
||||||
customProductRecyclerView.setAdapter(menuProductRecyclerAdapter);
|
customProductRecyclerView.setAdapter(menuProductRecyclerAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,36 +4,43 @@ import android.graphics.Rect;
|
|||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import ch.pizzamaxx.android.helper.DisplayHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by cimenmus on 20/09/2017.
|
* Created by cimenmus on 20/09/2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// This item decoration is for two column grid layout manager
|
|
||||||
public class GridSpacesItemDecoration extends RecyclerView.ItemDecoration {
|
public class GridSpacesItemDecoration extends RecyclerView.ItemDecoration {
|
||||||
|
|
||||||
private int space;
|
private int spanCount;
|
||||||
|
private int spacing;
|
||||||
|
private boolean includeEdge;
|
||||||
|
|
||||||
public GridSpacesItemDecoration(int space) {
|
public GridSpacesItemDecoration(int spanCount, int spacingInDp, boolean includeEdge) {
|
||||||
this.space = space;
|
this.spanCount = spanCount;
|
||||||
|
this.spacing = DisplayHelper.dpToPx(spacingInDp);
|
||||||
|
this.includeEdge = includeEdge;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||||
|
int position = parent.getChildAdapterPosition(view); // item position
|
||||||
|
int column = position % spanCount; // item column
|
||||||
|
|
||||||
outRect.left = space;
|
if (includeEdge) {
|
||||||
outRect.bottom = space;
|
outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
|
||||||
|
outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)
|
||||||
// Add top margin only for the first item to avoid double space between items
|
|
||||||
if (parent.getChildLayoutPosition(view) == 0 || parent.getChildLayoutPosition(view) == 1)
|
|
||||||
outRect.top = space;
|
|
||||||
else
|
|
||||||
outRect.top = 0;
|
|
||||||
|
|
||||||
// Add right margin only for the first item in the line to avoid double space between items
|
|
||||||
if (parent.getChildLayoutPosition(view) % 2 == 1)
|
|
||||||
outRect.right = space;
|
|
||||||
else
|
|
||||||
outRect.right = 0;
|
|
||||||
|
|
||||||
|
if (position < spanCount) { // top edge
|
||||||
|
outRect.top = spacing;
|
||||||
|
}
|
||||||
|
outRect.bottom = spacing; // item bottom
|
||||||
|
} else {
|
||||||
|
outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
|
||||||
|
outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing)
|
||||||
|
if (position >= spanCount) {
|
||||||
|
outRect.top = spacing; // item top
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:ignore="MissingPrefix"
|
tools:ignore="MissingPrefix"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="160dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="160dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="160dp"
|
android:layout_height="160dp"
|
||||||
android:background="@color/white">
|
android:background="@color/white">
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user