diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index 341398e..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-AndroidDragAndDropExample
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 97c5821..cfe4315 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -5,19 +5,14 @@
-
+
-
-
-
-
-
-
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 13e6014..7c1371c 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,8 +1,5 @@
-
-
-
@@ -43,19 +40,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..eada0df
--- /dev/null
+++ b/README.md
@@ -0,0 +1,7 @@
+GridLayoutManager with different view types flickering
+
+
+
+LinearLayoutManager with position dependent view types
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 4013af9..48c2c1b 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 24
- buildToolsVersion "24.0.1"
+ compileSdkVersion 23
+ buildToolsVersion "23.0.3"
defaultConfig {
applicationId "ru.rma.androiddraganddropexample"
minSdkVersion 14
- targetSdkVersion 24
+ targetSdkVersion 23
versionCode 1
versionName "1.0"
}
@@ -21,6 +21,6 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
- compile 'com.android.support:appcompat-v7:24.1.0'
- compile 'com.android.support:recyclerview-v7:24.1.0'
+ compile 'com.android.support:appcompat-v7:23.2.1'
+ compile 'com.android.support:recyclerview-v7:23.2.1'
}
diff --git a/app/src/main/java/ru/rma/androiddraganddropexample/ItemAdapter.java b/app/src/main/java/ru/rma/androiddraganddropexample/ItemAdapter.java
index a658bef..123eb93 100644
--- a/app/src/main/java/ru/rma/androiddraganddropexample/ItemAdapter.java
+++ b/app/src/main/java/ru/rma/androiddraganddropexample/ItemAdapter.java
@@ -55,7 +55,7 @@ public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_type_10, parent, false);
break;
default:
- throw new RuntimeException("Unknow view type: " + viewType);
+ throw new RuntimeException("Unknown view type: " + viewType);
}
return new ItemViewHolder(view);
}
diff --git a/app/src/main/java/ru/rma/androiddraganddropexample/MainActivity.java b/app/src/main/java/ru/rma/androiddraganddropexample/MainActivity.java
index 71a9432..419b397 100644
--- a/app/src/main/java/ru/rma/androiddraganddropexample/MainActivity.java
+++ b/app/src/main/java/ru/rma/androiddraganddropexample/MainActivity.java
@@ -4,6 +4,7 @@
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
+import android.support.v7.widget.RecyclerView;
import android.view.View;
@@ -37,14 +38,23 @@ public void onClick(View view) {
case R.id.btn_staggeredGridDiff:
startRecyclerViewActivity(RecyclerViewActivity.LAYOUT_MANAGER_STAGGERED_GRID, true);
break;
+ case R.id.btn_linearPositionDependentTypes:
+ startRecyclerViewActivity(RecyclerViewActivity.LAYOUT_MANAGER_LINEAR, true, true);
+ break;
}
}
private void startRecyclerViewActivity(int layoutManagerType, boolean diffViewTypes) {
+ startRecyclerViewActivity(layoutManagerType, diffViewTypes, false);
+ }
+
+ private void startRecyclerViewActivity(int layoutManagerType, boolean diffViewTypes,
+ boolean typesPosDependent) {
Intent intent = new Intent(this, RecyclerViewActivity.class);
intent.putExtra(RecyclerViewActivity.KEY_LAYOUT_MANAGER_TYPE, layoutManagerType);
intent.putExtra(RecyclerViewActivity.KEY_DIFFERENT_VIEW_TYPES, diffViewTypes);
+ intent.putExtra(RecyclerViewActivity.KEY_TYPES_POS_DEPENDENT, typesPosDependent);
ActivityCompat.startActivity(this, intent, null);
}
}
diff --git a/app/src/main/java/ru/rma/androiddraganddropexample/PositionTypeAdapter.java b/app/src/main/java/ru/rma/androiddraganddropexample/PositionTypeAdapter.java
new file mode 100644
index 0000000..0c57710
--- /dev/null
+++ b/app/src/main/java/ru/rma/androiddraganddropexample/PositionTypeAdapter.java
@@ -0,0 +1,22 @@
+package ru.rma.androiddraganddropexample;
+
+import android.support.annotation.NonNull;
+
+import java.util.List;
+
+public class PositionTypeAdapter extends ItemAdapter {
+ public PositionTypeAdapter(@NonNull List items) {
+ super(items);
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if(position == 0) {
+ return R.id.item_type_1;
+ } else if(position == getItemCount() - 1) {
+ return R.id.item_type_2;
+ } else {
+ return R.id.item_type_3;
+ }
+ }
+}
diff --git a/app/src/main/java/ru/rma/androiddraganddropexample/RecyclerViewActivity.java b/app/src/main/java/ru/rma/androiddraganddropexample/RecyclerViewActivity.java
index 60ad17f..5fd5430 100644
--- a/app/src/main/java/ru/rma/androiddraganddropexample/RecyclerViewActivity.java
+++ b/app/src/main/java/ru/rma/androiddraganddropexample/RecyclerViewActivity.java
@@ -1,6 +1,5 @@
package ru.rma.androiddraganddropexample;
-import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@@ -18,6 +17,7 @@ public class RecyclerViewActivity extends AppCompatActivity {
public static final String KEY_DIFFERENT_VIEW_TYPES = "ru.rma.androiddraganddropexample.RecyclerViewActivity.KEY_DIFFERENT_VIEW_TYPES";
public static final String KEY_LAYOUT_MANAGER_TYPE = "ru.rma.androiddraganddropexample.RecyclerViewActivity.KEY_LAYOUT_MANAGER_TYPE";
+ public static final String KEY_TYPES_POS_DEPENDENT = "ru.rma.androiddraganddropexample.RecyclerViewActivity.KEY_TYPES_POS_DEPENDENT";
public static final int LAYOUT_MANAGER_LINEAR = 1;
public static final int LAYOUT_MANAGER_GRID = 2;
public static final int LAYOUT_MANAGER_STAGGERED_GRID = 3;
@@ -27,7 +27,8 @@ public class RecyclerViewActivity extends AppCompatActivity {
private int mLayoutManagerType;
- private boolean isDifferentViewTypes;
+ private boolean mIsDifferentViewTypes;
+ private boolean mTypesPosDependent;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -39,19 +40,19 @@ protected void onCreate(Bundle savedInstanceState) {
ab.setDisplayHomeAsUpEnabled(true);
}
- Intent intent = getIntent();
- if (savedInstanceState != null) {
- isDifferentViewTypes = savedInstanceState.getBoolean(KEY_DIFFERENT_VIEW_TYPES, true);
- mLayoutManagerType = savedInstanceState.getInt(KEY_LAYOUT_MANAGER_TYPE, LAYOUT_MANAGER_LINEAR);
- } else if (intent != null) {
- isDifferentViewTypes = intent.getBooleanExtra(KEY_DIFFERENT_VIEW_TYPES, true);
- mLayoutManagerType = intent.getIntExtra(KEY_LAYOUT_MANAGER_TYPE, LAYOUT_MANAGER_LINEAR);
+ Bundle bundle = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
+ if (bundle != null) {
+ mIsDifferentViewTypes = bundle.getBoolean(KEY_DIFFERENT_VIEW_TYPES, true);
+ mLayoutManagerType = bundle.getInt(KEY_LAYOUT_MANAGER_TYPE, LAYOUT_MANAGER_LINEAR);
+ mTypesPosDependent = bundle.getBoolean(KEY_TYPES_POS_DEPENDENT, false);
} else {
- isDifferentViewTypes = true;
+ mIsDifferentViewTypes = true;
mLayoutManagerType = LAYOUT_MANAGER_LINEAR;
+ mTypesPosDependent = false;
}
-
- ItemAdapter adapter = new ItemAdapter(createItemList());
+ List models = createItemList();
+ ItemAdapter adapter = mTypesPosDependent ? new PositionTypeAdapter(models) :
+ new ItemAdapter(models);
RecyclerView rv = (RecyclerView) findViewById(R.id.rv_list);
switch (mLayoutManagerType) {
case LAYOUT_MANAGER_GRID:
@@ -76,13 +77,15 @@ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(KEY_LAYOUT_MANAGER_TYPE, mLayoutManagerType);
+ outState.putBoolean(KEY_DIFFERENT_VIEW_TYPES, mIsDifferentViewTypes);
+ outState.putBoolean(KEY_TYPES_POS_DEPENDENT, mTypesPosDependent);
}
private List createItemList() {
List list = new ArrayList<>();
- if (isDifferentViewTypes) {
+ if (mIsDifferentViewTypes) {
list.add(new ItemModel(R.id.item_type_1, "1"));
list.add(new ItemModel(R.id.item_type_2, "2"));
list.add(new ItemModel(R.id.item_type_3, "3"));
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 6173193..a3aaafc 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -62,4 +62,13 @@
android:onClick="onClick"
android:text="Staggered Grid Layout Manager Diff"
android:gravity="center_vertical|start"/>
+
+
diff --git a/pictures/grid.gif b/pictures/grid.gif
new file mode 100644
index 0000000..8faad8b
Binary files /dev/null and b/pictures/grid.gif differ
diff --git a/pictures/linear.gif b/pictures/linear.gif
new file mode 100644
index 0000000..ddfbc99
Binary files /dev/null and b/pictures/linear.gif differ