-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. 增加 3D Item 展示效果; 3. 解决小数取整导致的位置计算错误,Item 位置错乱问题
- Loading branch information
1 parent
36bb592
commit e63ac14
Showing
12 changed files
with
243 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/recycler/coverflow/CoverFlow3DActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.recycler.coverflow; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.TextView; | ||
|
||
import recycler.coverflow.CoverFlowLayoutManger; | ||
import recycler.coverflow.RecyclerCoverFlow; | ||
|
||
/** | ||
* 3D 旋转 | ||
* | ||
* @author Chen Xiaoping ([email protected]) | ||
* @version RecyclerCoverFlow | ||
* @Datetime 2020-09-01 09:21 | ||
* @since RecyclerCoverFlow | ||
*/ | ||
public class CoverFlow3DActivity extends AppCompatActivity implements Adapter.onItemClick { | ||
|
||
private RecyclerCoverFlow mList; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_just_coverflow); | ||
initList(); | ||
} | ||
|
||
private void initList() { | ||
mList = findViewById(R.id.list); | ||
mList.set3DItem(true); //3D 滚动 | ||
mList.setLoop(); //循环滚动 | ||
mList.setAdapter(new Adapter(this, this, true)); | ||
mList.setOnItemSelectedListener(new CoverFlowLayoutManger.OnSelected() { | ||
@Override | ||
public void onItemSelected(int position) { | ||
((TextView)findViewById(R.id.index)).setText((position+1)+"/"+mList.getLayoutManager().getItemCount()); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void clickItem(int pos) { | ||
mList.smoothScrollToPosition(pos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.recycler.coverflow; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.Canvas; | ||
import android.graphics.LinearGradient; | ||
import android.graphics.Matrix; | ||
import android.graphics.Paint; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.PorterDuffXfermode; | ||
import android.graphics.Shader; | ||
import android.graphics.drawable.BitmapDrawable; | ||
import android.graphics.drawable.Drawable; | ||
import android.support.annotation.Nullable; | ||
import android.util.AttributeSet; | ||
|
||
import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable; | ||
|
||
public class MirrorView extends android.support.v7.widget.AppCompatImageView { | ||
|
||
public MirrorView(Context context, AttributeSet attrs) { | ||
this(context, attrs, 0); | ||
} | ||
|
||
public MirrorView(Context context) { | ||
this(context, null, 0); | ||
} | ||
|
||
public MirrorView(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
if (getDrawable() != null) { | ||
doReflection(((BitmapDrawable) getDrawable()).getBitmap()); | ||
} | ||
} | ||
|
||
@Override | ||
public void setImageBitmap(Bitmap bm) { | ||
doReflection(bm); | ||
} | ||
|
||
@Override | ||
public void setImageDrawable(@Nullable Drawable drawable) { | ||
if (drawable == null) return; | ||
if (drawable instanceof GlideBitmapDrawable) { | ||
Bitmap bitmap = ((GlideBitmapDrawable) drawable).getBitmap(); | ||
if (bitmap != null) doReflection(bitmap); | ||
} else { | ||
super.setImageDrawable(drawable); | ||
} | ||
} | ||
|
||
@Override | ||
public void setImageResource(int resId) { | ||
doReflection(BitmapFactory.decodeResource(getResources(), resId)); | ||
} | ||
|
||
private void doReflection(Bitmap originalImage) { | ||
if (originalImage == null) return; | ||
final int reflectionGap = 4; | ||
int width = originalImage.getWidth(); | ||
int height = originalImage.getHeight(); | ||
|
||
Matrix matrix = new Matrix(); | ||
matrix.preScale(1, -1); | ||
|
||
Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, | ||
height / 2, width, height / 2, matrix, false); | ||
|
||
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, | ||
(height + height / 2), Bitmap.Config.ARGB_8888); | ||
|
||
Canvas canvas = new Canvas(bitmapWithReflection); | ||
|
||
canvas.drawBitmap(originalImage, 0, 0, null); | ||
|
||
Paint defaultPaint = new Paint(); | ||
canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint); | ||
|
||
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); | ||
|
||
Paint paint = new Paint(); | ||
LinearGradient shader = new LinearGradient(0, | ||
originalImage.getHeight(), 0, bitmapWithReflection.getHeight() | ||
+ reflectionGap, 0x70ffffff, 0x00000000, | ||
Shader.TileMode.MIRROR); | ||
|
||
paint.setShader(shader); | ||
|
||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); | ||
|
||
canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() | ||
+ reflectionGap, paint); | ||
super.setImageDrawable(new BitmapDrawable(getResources(), bitmapWithReflection)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout 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:orientation="vertical" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
app:cardElevation="1dp"> | ||
<com.recycler.coverflow.MirrorView | ||
android:id="@+id/img" | ||
android:layout_width="150dp" | ||
android:layout_height="200dp" | ||
android:scaleType="centerCrop" | ||
tools:src="@mipmap/item1"/> | ||
</FrameLayout> |
Oops, something went wrong.