use of android.support.v7.widget.LinearLayoutManager in project Fragmentation by YoKeyword.
the class FirstHomeFragment method initView.
private void initView(View view) {
mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
mRecy = (RecyclerView) view.findViewById(R.id.recy);
mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
mFab = (FloatingActionButton) view.findViewById(R.id.fab);
mToolbar.setTitle("首页");
mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
mRefreshLayout.setOnRefreshListener(this);
mAdapter = new FirstHomeAdapter(_mActivity);
LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
mRecy.setLayoutManager(manager);
mRecy.setAdapter(mAdapter);
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
FirstDetailFragment fragment = FirstDetailFragment.newInstance(mAdapter.getItem(position));
// LOLLIPOP(5.0)系统的 SharedElement支持有 系统BUG, 这里判断大于 > LOLLIPOP
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
setExitTransition(new Fade());
fragment.setEnterTransition(new Fade());
fragment.setSharedElementReturnTransition(new DetailTransition());
fragment.setSharedElementEnterTransition(new DetailTransition());
// 25.1.0以下的support包,Material过渡动画只有在进栈时有,返回时没有;
// 25.1.0+的support包,SharedElement正常
fragment.transaction().addSharedElement(((FirstHomeAdapter.VH) vh).img, getString(R.string.image_transition)).addSharedElement(((FirstHomeAdapter.VH) vh).tvTitle, "tv").commit();
}
start(fragment);
}
});
// Init Datas
List<Article> articleList = new ArrayList<>();
for (int i = 0; i < 15; i++) {
int index = i % 5;
Article article = new Article(mTitles[index], mImgRes[index]);
articleList.add(article);
}
mAdapter.setDatas(articleList);
mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
mScrollTotal += dy;
if (mScrollTotal <= 0) {
mInAtTop = true;
} else {
mInAtTop = false;
}
if (dy > 5) {
mFab.hide();
} else if (dy < -5) {
mFab.show();
}
}
});
mFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(_mActivity, "Action", Toast.LENGTH_SHORT).show();
}
});
}
use of android.support.v7.widget.LinearLayoutManager in project Fragmentation by YoKeyword.
the class FirstPagerFragment method initView.
private void initView(View view) {
EventBus.getDefault().register(this);
mRecy = (RecyclerView) view.findViewById(R.id.recy);
mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
mRefreshLayout.setOnRefreshListener(this);
mAdapter = new PagerAdapter(_mActivity);
mRecy.setHasFixedSize(true);
LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
mRecy.setLayoutManager(manager);
mRecy.setAdapter(mAdapter);
mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
mScrollTotal += dy;
if (mScrollTotal <= 0) {
mInAtTop = true;
} else {
mInAtTop = false;
}
}
});
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(int position, View view, RecyclerView.ViewHolder holder) {
// 通知MainActivity跳转至CycleFragment
EventBus.getDefault().post(new StartBrotherEvent(CycleFragment.newInstance(1)));
}
});
// Init Datas
List<String> items = new ArrayList<>();
for (int i = 0; i < 20; i++) {
String item = "联系人 " + i;
items.add(item);
}
mAdapter.setDatas(items);
}
use of android.support.v7.widget.LinearLayoutManager in project Fragmentation by YoKeyword.
the class FirstPagerFragment method initView.
private void initView(View view) {
mRecy = (RecyclerView) view.findViewById(R.id.recy);
mRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
mRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
mRefreshLayout.setOnRefreshListener(this);
mAdapter = new HomeAdapter(_mActivity);
LinearLayoutManager manager = new LinearLayoutManager(_mActivity);
mRecy.setLayoutManager(manager);
mRecy.setAdapter(mAdapter);
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(int position, View view, RecyclerView.ViewHolder vh) {
// 这里的DetailFragment在flow包里
// 这里是父Fragment启动,要注意 栈层级
((SupportFragment) getParentFragment()).start(DetailFragment.newInstance(mAdapter.getItem(position).getTitle()));
}
});
// Init Datas
List<Article> articleList = new ArrayList<>();
for (int i = 0; i < 15; i++) {
int index = (int) (Math.random() * 3);
Article article = new Article(mTitles[index], mContents[index]);
articleList.add(article);
}
mAdapter.setDatas(articleList);
mRecy.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
mScrollTotal += dy;
if (mScrollTotal <= 0) {
mAtTop = true;
} else {
mAtTop = false;
}
}
});
}
use of android.support.v7.widget.LinearLayoutManager in project Carbon by ZieIony.
the class IconTextListItemActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listcomponent);
Samples.initToolbar(this, getString(R.string.iconTextListItemActivity_title));
RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
recycler.setLayoutManager(new LinearLayoutManager(this));
RowListAdapter adapter = new RowListAdapter<>(DefaultIconTextItem.class, IconTextRow::new);
adapter.addFactory(DefaultIconSearchItem.class, parent -> new IconSearchRow(parent, new ArraySearchDataProvider(new String[] {}), filterResults -> {
}));
recycler.setAdapter(adapter);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(new ColorDrawable(Carbon.getThemeColor(this, R.attr.carbon_dividerColor)), getResources().getDimensionPixelSize(R.dimen.carbon_1dip));
dividerItemDecoration.setDrawRules(position -> position == 0);
recycler.addItemDecoration(dividerItemDecoration);
VectorDrawable drawable = new VectorDrawable(getResources(), R.raw.ic_face_24px);
adapter.setItems(Arrays.asList(new DefaultIconSearchItem(this), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text"), new DefaultIconTextItem(drawable, "text")));
}
use of android.support.v7.widget.LinearLayoutManager in project Carbon by ZieIony.
the class ImageTextSubtextDateListItemActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listcomponent);
Samples.initToolbar(this, getString(R.string.imageTextSubtextDateListItemActivity_title));
RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
recycler.setLayoutManager(new LinearLayoutManager(this));
RowListAdapter adapter = new RowListAdapter<>(DefaultImageTextSubtextDateItem.class, ImageTextSubtextDateRow::new);
adapter.addFactory(DefaultHeaderItem.class, PaddedHeaderRow.FACTORY);
recycler.setAdapter(adapter);
Drawable drawable = getResources().getDrawable(R.drawable.watermelon);
String date = format.format(new Date().getTime());
adapter.setItems(Arrays.asList(new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date)));
}
Aggregations