clean up horizontal card layout

This commit is contained in:
dkanada 2020-10-07 12:07:44 +09:00
commit 94f5478316
5 changed files with 15 additions and 10 deletions

View file

@ -35,7 +35,7 @@ public class HorizontalAlbumAdapter extends AlbumAdapter {
@Override
protected void setColors(int color, ViewHolder holder) {
if (holder.itemView != null) {
CardView card=(CardView)holder.itemView;
CardView card = (CardView) holder.itemView;
card.setCardBackgroundColor(color);
if (holder.title != null) {
holder.title.setTextColor(MaterialValueHelper.getPrimaryTextColor(activity, ColorUtil.isColorLight(color)));
@ -79,6 +79,6 @@ public class HorizontalAlbumAdapter extends AlbumAdapter {
@Override
public int getItemViewType(int position) {
return HorizontalAdapterHelper.getItemViewtype(position, getItemCount());
return HorizontalAdapterHelper.getItemViewType(position, getItemCount());
}
}

View file

@ -14,6 +14,9 @@ public class HorizontalAdapterHelper {
public static void applyMarginToLayoutParams(Context context, ViewGroup.MarginLayoutParams layoutParams, int viewType) {
int listMargin = context.getResources().getDimensionPixelSize(R.dimen.default_item_margin);
layoutParams.leftMargin = listMargin / 3;
layoutParams.rightMargin = listMargin / 3;
if (viewType == TYPE_FIRST) {
layoutParams.leftMargin = listMargin;
} else if (viewType == TYPE_LAST) {
@ -21,11 +24,13 @@ public class HorizontalAdapterHelper {
}
}
public static int getItemViewtype(int position, int itemCount) {
public static int getItemViewType(int position, int itemCount) {
if (position == 0) {
return TYPE_FIRST;
} else if (position == itemCount - 1) {
return TYPE_LAST;
} else return TYPE_MIDDLE;
} else {
return TYPE_MIDDLE;
}
}
}

View file

@ -160,13 +160,12 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/albums"
android:layout_width="match_parent"
android:layout_height="164dp"
android:layout_marginTop="16dp"
android:layout_height="wrap_content"
android:scrollbars="none" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_height="1dp"
android:background="?attr/dividerColor" />
<androidx.recyclerview.widget.RecyclerView

View file

@ -2,8 +2,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="104dp"
android:layout_height="148dp"
android:layout_marginEnd="8dp"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:foreground="?attr/rectSelectorStrong"
app:cardBackgroundColor="?cardBackgroundColor">
@ -30,6 +30,8 @@
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
tools:ignore="UnusedAttribute">
<TextView

View file

@ -12,7 +12,6 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|start"
android:layout_marginStart="-8dp"
android:tint="?attr/iconColor"
android:tintMode="src_in"
android:visibility="gone"