-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
211 additions
and
47 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
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
106 changes: 106 additions & 0 deletions
106
app/src/main/java/github/hellocsl/gallerylayoutmanager/TestActivity.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,106 @@ | ||
package github.hellocsl.gallerylayoutmanager; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.TextView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import butterknife.BindView; | ||
import butterknife.ButterKnife; | ||
import butterknife.OnClick; | ||
import github.hellocsl.gallerylayoutmanager.adapter.DemoAdapter; | ||
import github.hellocsl.gallerylayoutmanager.layout.impl.ScaleTransformer; | ||
import github.hellocsl.layoutmanager.gallery.GalleryLayoutManager; | ||
|
||
/** | ||
* Created by chensuilun on 2017/3/24. | ||
*/ | ||
|
||
public class TestActivity extends AppCompatActivity { | ||
private static final String TAG = "TestActivity"; | ||
@BindView(R.id.main_recycle1) | ||
RecyclerView mMainRecycle1; | ||
@BindView(R.id.main_tv_recycle_info_1) | ||
TextView mMainTvRecycleInfo1; | ||
@BindView(R.id.main_recycle2) | ||
RecyclerView mMainRecycle2; | ||
@BindView(R.id.main_tv_recycle_info_2) | ||
TextView mMainTvRecycleInfo2; | ||
@BindView(R.id.main_tv_recycle_info_3) | ||
TextView mMainTvRecycleInfo3; | ||
@BindView(R.id.main_btn_random) | ||
Button mMainBtnRandom; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.fragment_test); | ||
ButterKnife.bind(this); | ||
initView(); | ||
} | ||
|
||
private void initView() { | ||
final List<String> title = new ArrayList<String>(); | ||
int size = 50; | ||
for (int i = 0; i < size; i++) { | ||
title.add("Hello" + i); | ||
} | ||
GalleryLayoutManager layoutManager1 = new GalleryLayoutManager(GalleryLayoutManager.HORIZONTAL); | ||
layoutManager1.attach(mMainRecycle1, 30); | ||
layoutManager1.setItemTransformer(new ScaleTransformer()); | ||
DemoAdapter demoAdapter1 = new DemoAdapter(title) { | ||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
mMainTvRecycleInfo1.append("Create VH type:+" + viewType + "\n"); | ||
return super.onCreateViewHolder(parent, viewType); | ||
} | ||
}; | ||
demoAdapter1.setOnItemClickListener(new DemoAdapter.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(View view, int position) { | ||
mMainRecycle1.smoothScrollToPosition(position); | ||
} | ||
}); | ||
mMainRecycle1.setAdapter(demoAdapter1); | ||
|
||
final GalleryLayoutManager layoutManager2 = new GalleryLayoutManager(GalleryLayoutManager.VERTICAL); | ||
layoutManager2.attach(mMainRecycle2, 20); | ||
layoutManager2.setCallbackInFling(true); | ||
layoutManager2.setOnItemSelectedListener(new GalleryLayoutManager.OnItemSelectedListener() { | ||
@Override | ||
public void onItemSelected(RecyclerView recyclerView, View item, int position) { | ||
if (BuildConfig.DEBUG) { | ||
Log.d(TAG, "onItemSelected: " + item.isSelected()); | ||
} | ||
mMainTvRecycleInfo2.setText("selected:" + position + "\n"); | ||
} | ||
}); | ||
DemoAdapter demoAdapter2 = new DemoAdapter(title, DemoAdapter.VIEW_TYPE_TEXT); | ||
demoAdapter2.setOnItemClickListener(new DemoAdapter.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(View view, int position) { | ||
mMainRecycle2.smoothScrollToPosition(position); | ||
} | ||
}); | ||
mMainRecycle2.setAdapter(demoAdapter2); | ||
} | ||
|
||
private final Random mRandom = new Random(); | ||
|
||
@OnClick(R.id.main_btn_random) | ||
public void onClick() { | ||
int selectPosition = mRandom.nextInt(50); | ||
mMainRecycle1.smoothScrollToPosition(selectPosition); | ||
mMainRecycle2.smoothScrollToPosition(selectPosition); | ||
} | ||
|
||
} |
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
22 changes: 11 additions & 11 deletions
22
app/src/main/java/github/hellocsl/gallerylayoutmanager/layout/impl/CurveTransformer.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 |
---|---|---|
@@ -1,35 +1,35 @@ | ||
package github.hellocsl.gallerylayoutmanager.layout.impl; | ||
|
||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import github.hellocsl.gallerylayoutmanager.BuildConfig; | ||
import github.hellocsl.layoutmanager.gallery.GalleryLayoutManager; | ||
|
||
/** | ||
* Created by chensuilun on 2016/12/16. | ||
*/ | ||
public class CurveTransformer implements GalleryLayoutManager.ItemTransformer { | ||
|
||
public static final int ROTATE_ANGEL = 7; | ||
private static final String TAG = "CurveTransformer"; | ||
|
||
|
||
@Override | ||
public void transformItem(GalleryLayoutManager layoutManager, View item, float fraction) { | ||
if (BuildConfig.DEBUG) { | ||
Log.d(TAG, "transformItem() called with: fraction = [" + fraction + "]"); | ||
} | ||
if (layoutManager.getOrientation() == GalleryLayoutManager.VERTICAL) { | ||
return; | ||
} | ||
item.setPivotX(item.getWidth() / 2.f); | ||
item.setPivotY(item.getHeight()); | ||
int width = item.getWidth(); | ||
int height = item.getHeight(); | ||
item.setPivotX(width / 2.f); | ||
item.setPivotY(height); | ||
float scale = 1 - 0.1f * Math.abs(fraction); | ||
item.setScaleX(scale); | ||
item.setScaleY(scale); | ||
item.setRotation(10 * fraction); | ||
item.setTranslationY(30 * Math.abs(fraction)); | ||
item.setTranslationX(50 * -fraction); | ||
item.setRotation(ROTATE_ANGEL * fraction); | ||
item.setTranslationY((float) (Math.sin(2 * Math.PI * ROTATE_ANGEL * Math.abs(fraction) / 360.f) * width / 2.0f)); | ||
item.setTranslationX((float) ((1 - scale) * width / 2.0f / Math.cos(2 * Math.PI * ROTATE_ANGEL * fraction / 360.f))); | ||
if (fraction > 0) { | ||
item.setTranslationX(-item.getTranslationX()); | ||
} | ||
item.setAlpha(1 - 0.2f * Math.abs(fraction)); | ||
} | ||
} |
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
Oops, something went wrong.