├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── rk_attrs.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── item1.jpg
│ │ │ │ ├── item2.jpg
│ │ │ │ ├── item3.jpg
│ │ │ │ ├── item4.jpg
│ │ │ │ ├── item5.jpg
│ │ │ │ ├── item6.jpg
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── layout_image.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── cn
│ │ │ └── xmrk
│ │ │ └── layoutmanager
│ │ │ ├── RoundImageView.java
│ │ │ ├── MainActivity.java
│ │ │ ├── CustomImageView.java
│ │ │ └── CustomLayoutManager.java
│ ├── test
│ │ └── java
│ │ │ └── cn
│ │ │ └── xmrk
│ │ │ └── layoutmanager
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── cn
│ │ └── xmrk
│ │ └── layoutmanager
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── demo.gif
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/demo.gif
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LayoutManagerDemo
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/item1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/item1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/item2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/item2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/item3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/item3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/item4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/item4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/item5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/item5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/item6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/item6.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hzl123456/CustomLayoutManager/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CustomLayoutManager
2 | 改造LayoutManager实现弧形滚动和中间放大的效果
3 |
4 | 
5 |
6 | 简书地址:http://www.jianshu.com/p/e01543e5164c
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/rk_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/cn/xmrk/layoutmanager/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.xmrk.layoutmanager;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.1"
6 | defaultConfig {
7 | applicationId "cn.xmrk.layoutmanager"
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:appcompat-v7:24.2.0'
23 | compile 'com.android.support:recyclerview-v7:24.2.0'
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/cn/xmrk/layoutmanager/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.xmrk.layoutmanager;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("cn.xmrk.layoutmanager", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/xmrk/layoutmanager/RoundImageView.java:
--------------------------------------------------------------------------------
1 | package cn.xmrk.layoutmanager;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.RectF;
9 | import android.util.AttributeSet;
10 |
11 | /**
12 | *
13 | */
14 | public class RoundImageView extends CustomImageView {
15 |
16 | public RoundImageView(Context context) {
17 | super(context);
18 | }
19 |
20 | public RoundImageView(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 |
23 | }
24 |
25 | public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
26 | super(context, attrs, defStyle);
27 |
28 | }
29 |
30 | public static Bitmap getBitmap(int width, int height) {
31 | Bitmap bitmap = Bitmap.createBitmap(width, height,
32 | Bitmap.Config.ARGB_8888);
33 | Canvas canvas = new Canvas(bitmap);
34 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
35 | paint.setColor(Color.BLACK);
36 | canvas.drawOval(new RectF(0.0f, 0.0f, width, height), paint);
37 | return bitmap;
38 | }
39 |
40 | @Override
41 | public Bitmap getBitmap() {
42 | return getBitmap(getWidth(), getHeight());
43 | }
44 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/xmrk/layoutmanager/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cn.xmrk.layoutmanager;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.TypedValue;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.Toast;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 |
14 | private RecyclerView rvContent;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 |
21 | rvContent = (RecyclerView) findViewById(R.id.rv_content);
22 | rvContent.setLayoutManager(new CustomLayoutManager(dip2px(250)));
23 | rvContent.setAdapter(new Adapter());
24 |
25 | findViewById(R.id.btn_smooth).setOnClickListener(new View.OnClickListener() {
26 | @Override
27 | public void onClick(View view) {
28 | rvContent.smoothScrollToPosition(5);
29 | }
30 | });
31 | }
32 |
33 | /**
34 | * dp转像素
35 | *
36 | * @param dpValue
37 | * @return
38 | */
39 | public final int dip2px(float dpValue) {
40 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, getResources().getDisplayMetrics());
41 | }
42 |
43 |
44 | class Adapter extends RecyclerView.Adapter {
45 | @Override
46 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
47 | return new MyViewHolder(LayoutInflater.from(MainActivity.this).inflate(R.layout.layout_image, parent, false));
48 | }
49 |
50 | @Override
51 | public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
52 | int index = (position + 1) % 6;
53 | int res = 0;
54 | switch (index) {
55 | case 0:
56 | res = R.mipmap.item1;
57 | break;
58 | case 1:
59 | res = R.mipmap.item2;
60 | break;
61 | case 2:
62 | res = R.mipmap.item3;
63 | break;
64 | case 3:
65 | res = R.mipmap.item4;
66 | break;
67 | case 4:
68 | res = R.mipmap.item5;
69 | break;
70 | case 5:
71 | res = R.mipmap.item6;
72 | break;
73 | }
74 | ((MyViewHolder) holder).imageView.setImageResource(res);
75 | ((MyViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
76 | @Override
77 | public void onClick(View v) {
78 | Toast.makeText(MainActivity.this, "点击了第" + position + "项目", Toast.LENGTH_SHORT).show();
79 | }
80 | });
81 | }
82 |
83 | @Override
84 | public int getItemCount() {
85 | return 20;
86 | }
87 |
88 | class MyViewHolder extends RecyclerView.ViewHolder {
89 | RoundImageView imageView;
90 |
91 | public MyViewHolder(View itemView) {
92 | super(itemView);
93 | imageView = (RoundImageView) itemView.findViewById(R.id.image);
94 |
95 | }
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/xmrk/layoutmanager/CustomImageView.java:
--------------------------------------------------------------------------------
1 | package cn.xmrk.layoutmanager;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.PorterDuff;
10 | import android.graphics.PorterDuffXfermode;
11 | import android.graphics.Rect;
12 | import android.graphics.Xfermode;
13 | import android.graphics.drawable.Drawable;
14 | import android.util.AttributeSet;
15 | import android.view.Display;
16 | import android.view.WindowManager;
17 | import android.widget.ImageView;
18 |
19 | import java.lang.ref.WeakReference;
20 |
21 | /**
22 | * Created by Mostafa Gazar on 11/2/13.
23 | */
24 | public abstract class CustomImageView extends ImageView {
25 |
26 | protected Context mContext;
27 |
28 | private static final Xfermode sXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
29 | private Bitmap mMaskBitmap;
30 | private Paint mPaint;
31 | private WeakReference mWeakBitmap;
32 |
33 | /**
34 | * 宽度比率
35 | */
36 | private int ratioWidth;
37 |
38 | /**
39 | * 高度比率
40 | */
41 | private int ratioHeight;
42 |
43 | public CustomImageView(Context context) {
44 | super(context);
45 | sharedConstructor(context);
46 | }
47 |
48 | public CustomImageView(Context context, AttributeSet attrs) {
49 | super(context, attrs);
50 | sharedConstructor(context);
51 | init(context, attrs);
52 | }
53 |
54 | public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
55 | super(context, attrs, defStyle);
56 | sharedConstructor(context);
57 | init(context, attrs);
58 | }
59 |
60 | private void init(Context context, AttributeSet attrs) {
61 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CustomImageView);
62 | ratioWidth = ta.getInt(R.styleable.CustomImageView_ratio_width, 1);
63 | ratioHeight = ta.getInt(R.styleable.CustomImageView_ratio_height, 1);
64 | ta.recycle();
65 | }
66 |
67 | private void sharedConstructor(Context context) {
68 | mContext = context;
69 |
70 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
71 |
72 | }
73 |
74 | @Override
75 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
76 | Drawable drawable = getDrawable();
77 | if (drawable == null) {
78 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
79 | } else {
80 | int width = getWidth() > 0 ? getWidth() : MeasureSpec.getSize(widthMeasureSpec);// PhoneUtil.getScreenDisplay().x;
81 | if (width == 0) {
82 | width = getScreenDisplay().getWidth();
83 | }
84 | if (width > 0) {
85 | float es = (float) width / (float) drawable.getIntrinsicWidth();
86 | int height;
87 | if (ratioWidth > 0 && ratioHeight > 0) {
88 | // 比率不为0且不相等的时候,高度不取图片高度,而是按比例根据宽度计算高度
89 | height = (int) ((float) width / ratioWidth * ratioHeight);
90 | } else {
91 | height = (int) (drawable.getIntrinsicHeight() * es);
92 | }
93 | setMeasuredDimension(width, height);
94 | }
95 | }
96 | }
97 |
98 | public void invalidate() {
99 | mWeakBitmap = null;
100 | if (mMaskBitmap != null) {
101 | mMaskBitmap.recycle();
102 | }
103 | super.invalidate();
104 | }
105 |
106 | @SuppressLint("DrawAllocation")
107 | @Override
108 | protected void onDraw(Canvas canvas) {
109 | if (!isInEditMode()) {
110 | int i = canvas.saveLayer(0.0f, 0.0f, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
111 | try {
112 | Bitmap bitmap = mWeakBitmap != null ? mWeakBitmap.get() : null;
113 | // Bitmap not loaded.
114 | if (bitmap == null || bitmap.isRecycled()) {
115 | Drawable drawable = getDrawable();
116 | if (drawable != null) {
117 | // Allocation onDraw but it's ok because it will not
118 | // always be called.
119 | bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
120 | Canvas bitmapCanvas = new Canvas(bitmap);
121 | // drawable.setBounds(0, 0, getWidth(), getHeight());
122 | // drawable.draw(bitmapCanvas);
123 | super.onDraw(bitmapCanvas);
124 |
125 | // If mask is already set, skip and use cached mask.
126 | if (mMaskBitmap == null || mMaskBitmap.isRecycled()) {
127 | mMaskBitmap = getBitmap();
128 | }
129 |
130 | // Draw Bitmap.
131 | mPaint.reset();
132 | mPaint.setFilterBitmap(false);
133 | mPaint.setXfermode(sXfermode);
134 | // mBitmapShader = new BitmapShader(mMaskBitmap,
135 | // Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
136 | // mPaint.setShader(mBitmapShader);
137 | bitmapCanvas.drawBitmap(mMaskBitmap, 0.0f, 0.0f, mPaint);
138 |
139 | mWeakBitmap = new WeakReference(bitmap);
140 | }
141 | }
142 | // Bitmap already loaded.
143 | if (bitmap != null) {
144 | mPaint.setXfermode(null);
145 | // mPaint.setShader(null);
146 | // canvas.drawBitmap(bitmap, 0.0f, 0.0f, mPaint);
147 | canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), new Rect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight()
148 | - getPaddingBottom()), mPaint);
149 | return;
150 | }
151 | } catch (Exception e) {
152 | System.gc();
153 | } finally {
154 | canvas.restoreToCount(i);
155 | }
156 | } else {
157 | super.onDraw(canvas);
158 | }
159 | }
160 |
161 | public abstract Bitmap getBitmap();
162 |
163 | /**
164 | * 返回屏幕数据
165 | *
166 | * @return
167 | */
168 | public Display getScreenDisplay() {
169 | WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
170 | return wm.getDefaultDisplay();
171 | }
172 |
173 | }
--------------------------------------------------------------------------------
/app/src/main/java/cn/xmrk/layoutmanager/CustomLayoutManager.java:
--------------------------------------------------------------------------------
1 | package cn.xmrk.layoutmanager;
2 |
3 | import android.graphics.PointF;
4 | import android.support.v7.widget.LinearSmoothScroller;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.SparseArray;
7 | import android.util.SparseBooleanArray;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | /**
12 | * Created by Au61 on 2016/10/10.
13 | */
14 |
15 | public class CustomLayoutManager extends RecyclerView.LayoutManager {
16 |
17 | /**
18 | * 最大放大倍数
19 | **/
20 | private static final float SCALE_RATE = 1.4f;
21 |
22 | /**
23 | * 默认每个item之间的角度
24 | **/
25 | private static float INTERVAL_ANGLE = 30f;
26 |
27 |
28 | /**
29 | * 滑动距离和角度的一个比例
30 | **/
31 | private static float DISTANCE_RATIO = 10f;
32 |
33 | /**
34 | * 默认的半径长度
35 | **/
36 | private static final int DEFAULT_RADIO = 100;
37 | /**
38 | * 滑动的方向
39 | */
40 | private static int SCROLL_LEFT = 1;
41 | private static int SCROLL_RIGHT = 2;
42 |
43 | /**
44 | * 半径默认为100
45 | **/
46 | private int mRadius;
47 | /**
48 | * 当前旋转的角度
49 | **/
50 | private float offsetRotate;
51 |
52 | private int startLeft;
53 | private int startTop;
54 | /**
55 | * 第一个的角度是为0
56 | **/
57 | private int firstChildRotate = 0;
58 |
59 | //放大的倍数
60 | private float maxScale;
61 |
62 | //在什么角度变化之内
63 | private float minScaleRotate = 40;
64 |
65 | //每个item之间的角度间隔
66 | private float intervalAngle;
67 |
68 | //最大和最小的移除角度
69 | private int minRemoveDegree;
70 | private int maxRemoveDegree;
71 |
72 | //记录Item是否出现过屏幕且还没有回收。true表示出现过屏幕上,并且还没被回收
73 | private SparseBooleanArray itemAttached = new SparseBooleanArray();
74 | //保存所有的Item的上下左右的偏移量信息
75 | private SparseArray itemsRotate = new SparseArray<>();
76 |
77 |
78 | // 这里的每个item的大小都是一样的
79 | private int mDecoratedChildWidth;
80 | private int mDecoratedChildHeight;
81 |
82 |
83 | public CustomLayoutManager() {
84 | this(DEFAULT_RADIO);
85 | }
86 |
87 |
88 | public CustomLayoutManager(int mRadius) {
89 | this.mRadius = mRadius;
90 | offsetRotate = 0;
91 | intervalAngle = INTERVAL_ANGLE;
92 | maxScale = SCALE_RATE;
93 | minRemoveDegree = -120;
94 | maxRemoveDegree = 120;
95 | }
96 |
97 |
98 | @Override
99 | public RecyclerView.LayoutParams generateDefaultLayoutParams() {
100 | return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
101 | }
102 |
103 | @Override
104 | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
105 | //如果没有item,直接返回
106 | //跳过preLayout,preLayout主要用于支持动画
107 | if (getItemCount() <= 0 || state.isPreLayout()) {
108 | offsetRotate = 0;
109 | return;
110 | }
111 | //得到子view的宽和高,这边的item的宽高都是一样的,所以只需要进行一次测量
112 | View scrap = recycler.getViewForPosition(0);
113 | addView(scrap);
114 | measureChildWithMargins(scrap, 0, 0);
115 | //计算测量布局的宽高
116 | mDecoratedChildWidth = getDecoratedMeasuredWidth(scrap);
117 | mDecoratedChildHeight = getDecoratedMeasuredHeight(scrap);
118 | //确定起始位置,在最上方的中心处
119 | startLeft = (getHorizontalSpace() - mDecoratedChildWidth) / 2;
120 | startTop = 0;
121 |
122 | //记录每个item旋转的角度
123 | float rotate = firstChildRotate;
124 | for (int i = 0; i < getItemCount(); i++) {
125 | itemsRotate.put(i, rotate);
126 | itemAttached.put(i, false);
127 | rotate += intervalAngle;
128 | }
129 |
130 | //在布局之前,将所有的子View先Detach掉,放入到Scrap缓存中
131 | detachAndScrapAttachedViews(recycler);
132 | fixRotateOffset();
133 | layoutItems(recycler, state);
134 | }
135 |
136 | /**
137 | * 进行view的回收和显示
138 | **/
139 | private void layoutItems(RecyclerView.Recycler recycler, RecyclerView.State state) {
140 | layoutItems(recycler, state, SCROLL_RIGHT);
141 | }
142 |
143 | /**
144 | * 进行view的回收和显示的具体实现
145 | **/
146 | private void layoutItems(RecyclerView.Recycler recycler,
147 | RecyclerView.State state, int oritention) {
148 | if (state.isPreLayout()) return;
149 |
150 | //移除界面之外的view
151 | for (int i = 0; i < getChildCount(); i++) {
152 | View view = getChildAt(i);
153 | int position = getPosition(view);
154 | if (itemsRotate.get(position) - offsetRotate > maxRemoveDegree
155 | || itemsRotate.get(position) - offsetRotate < minRemoveDegree) {
156 | itemAttached.put(position, false);
157 | removeAndRecycleView(view, recycler);
158 | }
159 | }
160 |
161 | //将要显示的view进行显示出来
162 | for (int i = 0; i < getItemCount(); i++) {
163 | if (itemsRotate.get(i) - offsetRotate <= maxRemoveDegree
164 | && itemsRotate.get(i) - offsetRotate >= minRemoveDegree) {
165 | if (!itemAttached.get(i)) {
166 | View scrap = recycler.getViewForPosition(i);
167 | measureChildWithMargins(scrap, 0, 0);
168 | if (oritention == SCROLL_LEFT)
169 | addView(scrap, 0);
170 | else
171 | addView(scrap);
172 | float rotate = itemsRotate.get(i) - offsetRotate;
173 |
174 | int left = calLeftPosition(rotate);
175 | int top = calTopPosition(rotate);
176 |
177 | scrap.setRotation(rotate);
178 |
179 | layoutDecorated(scrap, startLeft + left, startTop + top,
180 | startLeft + left + mDecoratedChildWidth, startTop + top + mDecoratedChildHeight);
181 |
182 | itemAttached.put(i, true);
183 |
184 | //计算角度然后进行放大
185 | float scale = calculateScale(rotate);
186 | scrap.setScaleX(scale);
187 | scrap.setScaleY(scale);
188 | }
189 | }
190 | }
191 | }
192 |
193 |
194 | /**
195 | * 根据角度计算大小,0度的时候最大,minScaleRotate度的时候最小,然后其他时候变小
196 | **/
197 | private float calculateScale(float rotate) {
198 | rotate = Math.abs(rotate) > minScaleRotate ? minScaleRotate : Math.abs(rotate);
199 | return (1 - rotate / minScaleRotate) * (maxScale - 1) + 1;
200 | }
201 |
202 |
203 | @Override
204 | public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
205 | int willScroll = dx;
206 |
207 | //每个item x方向上的移动距离
208 | float theta = dx / DISTANCE_RATIO;
209 | float targetRotate = offsetRotate + theta;
210 |
211 | //目标角度
212 | if (targetRotate < 0) {
213 | willScroll = (int) (-offsetRotate * DISTANCE_RATIO);
214 | } else if (targetRotate > getMaxOffsetDegree()) {
215 | willScroll = (int) ((getMaxOffsetDegree() - offsetRotate) * DISTANCE_RATIO);
216 | }
217 | theta = willScroll / DISTANCE_RATIO;
218 |
219 | //当前移动的总角度
220 | offsetRotate += theta;
221 |
222 | //重新设置每个item的x和y的坐标
223 | for (int i = 0; i < getChildCount(); i++) {
224 | View view = getChildAt(i);
225 | float newRotate = view.getRotation() - theta;
226 | int offsetX = calLeftPosition(newRotate);
227 | int offsetY = calTopPosition(newRotate);
228 |
229 | layoutDecorated(view, startLeft + offsetX, startTop + offsetY,
230 | startLeft + offsetX + mDecoratedChildWidth, startTop + offsetY + mDecoratedChildHeight);
231 | view.setRotation(newRotate);
232 |
233 | //计算角度然后进行放大
234 | float scale = calculateScale(newRotate);
235 | view.setScaleX(scale);
236 | view.setScaleY(scale);
237 | }
238 |
239 | //根据dx的大小判断是左滑还是右滑
240 | if (dx < 0)
241 | layoutItems(recycler, state, SCROLL_LEFT);
242 | else
243 | layoutItems(recycler, state, SCROLL_RIGHT);
244 | return willScroll;
245 | }
246 |
247 | @Override
248 | public boolean canScrollHorizontally() {
249 | return true;
250 | }
251 |
252 | /**
253 | * 当前item的x的坐标
254 | **/
255 | private int calLeftPosition(float rotate) {
256 | return (int) (mRadius * Math.cos(Math.toRadians(90 - rotate)));
257 | }
258 |
259 | /**
260 | * 当前item的y的坐标
261 | **/
262 | private int calTopPosition(float rotate) {
263 | return (int) ( mRadius * Math.sin(Math.toRadians(90 - rotate)));
264 | }
265 |
266 | /**
267 | * 设置滚动时候的角度
268 | **/
269 | private void fixRotateOffset() {
270 | if (offsetRotate < 0) {
271 | offsetRotate = 0;
272 | }
273 | if (offsetRotate > getMaxOffsetDegree()) {
274 | offsetRotate = getMaxOffsetDegree();
275 | }
276 |
277 | }
278 |
279 | /**
280 | * 最大的角度
281 | **/
282 | private float getMaxOffsetDegree() {
283 | return (getItemCount() - 1) * intervalAngle;
284 | }
285 |
286 | private int getHorizontalSpace() {
287 | return getWidth() - getPaddingRight() - getPaddingLeft();
288 | }
289 |
290 | private int getVerticalSpace() {
291 | return getHeight() - getPaddingBottom() - getPaddingTop();
292 | }
293 |
294 |
295 | private PointF computeScrollVectorForPosition(int targetPosition) {
296 | if (getChildCount() == 0) {
297 | return null;
298 | }
299 | final int firstChildPos = getPosition(getChildAt(0));
300 | final int direction = targetPosition < firstChildPos ? -1 : 1;
301 | return new PointF(direction, 0);
302 | }
303 |
304 |
305 | @Override
306 | public void scrollToPosition(int position) {//移动到某一项
307 | if (position < 0 || position > getItemCount() - 1) return;
308 | float targetRotate = position * intervalAngle;
309 | if (targetRotate == offsetRotate) return;
310 | offsetRotate = targetRotate;
311 | fixRotateOffset();
312 | requestLayout();
313 | }
314 |
315 | @Override
316 | public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {//平滑的移动到某一项
317 | LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
318 | @Override
319 | public PointF computeScrollVectorForPosition(int targetPosition) {
320 | return CustomLayoutManager.this.computeScrollVectorForPosition(targetPosition);
321 | }
322 |
323 | };
324 | smoothScroller.setTargetPosition(position);
325 | startSmoothScroll(smoothScroller);
326 | }
327 |
328 | @Override
329 | public void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter) {//adapter进行改变的时候
330 | removeAllViews();
331 | offsetRotate = 0;
332 | }
333 |
334 | }
335 |
--------------------------------------------------------------------------------