所以我想要的是交错布局,但列表中的第一项需要跨越两列.前两行也是固定高度.除了第一个项目跨越两列,我的一切都在工作.
我正在使用带有StaggeredGridLayoutManager的RecyclerView.Adapter.似乎不是开箱即用的功能.我假设我可以制作一个自定义布局管理器我不知道从哪里开始.我尝试过搜索,但我找不到任何关于如何让项目跨越多列的信息.
下面的图片是我在列表中寻找的内容.

我有一个Recycler View,其中包含从内部存储加载的图像.我想点击时突出显示所选项目.我尝试了很多东西,但它没有用.实际上我需要的是当我点击Recycler View中的任何项目时,Item必须进入My ArrayList,它也应该突出显示,当我点击或说取消选择时它必须再次变为正常.这是我的代码:
public class Images extends Fragment {
private List<ImageHolder> imageList;
Cursor imageCursor;
RecyclerView recyclerView;
MyImageAdapter adapter;
ActionButton clickButton;
List<String> listofImages;
List<Integer> pos;
int columnIndex;
StringBuilder stringBuilder;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootlayout = inflater.inflate(R.layout.image, container, false);
listofImages=new ArrayList<String>();
pos=new ArrayList<Integer>();
stringBuilder=new StringBuilder();
ContentResolver imageResolver = getActivity().getContentResolver();
Uri imageUri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String projection[]={MediaStore.Images.Thumbnails._ID,MediaStore.Images.Media.TITLE};
imageCursor = getActivity().managedQuery(imageUri, projection, null, null, null);
clickButton= (ActionButton) rootlayout.findViewById(R.id.action_button);
recyclerView = (RecyclerView) rootlayout.findViewById(R.id.recycler_view_image);
adapter = new MyImageAdapter(getActivity(), getImageList()); …Run Code Online (Sandbox Code Playgroud) 我正在使用CoordinatorLayout来自的视图android.support.design.我想附加app:layout_behavior片段的RecyclerView?
在Google提供的示例中,它们仅将其附加到附加RecyclerView的相同XML文件中CoordinatorLayout.
有没有办法附加CoordinatorLayout到片段RecyclerView内ViewPager?
样品是在这个博客帖子在Android开发者博客.
android android-appcompat android-recyclerview android-design-library android-coordinatorlayout
我正在使用基本的RecyclerView和GridLayoutManager.我观察到,smoothScrollToPosition和scrollToPosition也没有正常工作.
a)使用时smoothScrollToPosition我经常收到错误RecyclerView
"RecyclerView:平滑滚动时传递到目标位置."
并且RecyclerView没有正确滚动(通常它会错过目标行).这主要是在我试图滚动到某行的第一项时
b)使用scrollToPosition它时似乎工作得很好但是大多数时候我只能看到行的第一项而其余的都没有显示.
你能给我一些提示,如何正确地完成至少一种方法吗?
非常感谢!
android scroll smooth-scrolling gridlayoutmanager android-recyclerview
我在NestedScrollview中有一个Recyclerview ..一切正常,除了一个thig.我在NestedScrollview中有三个视图,前两个是LinearLayout然后是Recyclerview.当我运行我的应用程序时,活动不显示前两个布局,它从Recyclerview的顶部开始.
它如何显示我的布局:
它的假设如何显示:
我在viewpager下加载这个enite布局,我的viewpager是Coordinator Layout的子代.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/home_layout_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.daimajia.slider.library.SliderLayout
android:id="@+id/image_slider"
android:layout_width="match_parent"
android:layout_height="@dimen/image_slider_height"
android:layout_marginTop="@dimen/image_slider_top_margin" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/popular_fragment_side_padding"
android:layout_marginRight="@dimen/popular_fragment_side_padding"
android:layout_marginTop="@dimen/popular_fragment_side_padding"
android:orientation="horizontal"
android:weightSum="4">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/free_delivery"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_centerInParent="true"
android:background="@color/white">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="@+id/btnImageViewFreeDelivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/icon_free_delivery" />
<TextView
android:id="@+id/btnTextFreeDelivery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnImageViewFreeDelivery"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:text="@string/free_delivery_txt"
android:textColor="@color/popular_fragment_four_btn_txt"
android:textSize="@dimen/popular_fragment_four_btn_txt_size" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<RelativeLayout
android:id="@+id/flash_deals"
android:layout_width="76dp"
android:layout_height="76dp" …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用recylerview,每当将新元素添加到recyclerview时,它就会使用滚动到最后一个元素
recyclerView.scrollToPosition(adapter.getCount());
Run Code Online (Sandbox Code Playgroud)
但是,每当键盘打开时(因为editTextView),它会调整视图大小并且recyclerview变小,但无法滚动到最后一个元素.
android:windowSoftInputMode="adjustResize"
Run Code Online (Sandbox Code Playgroud)
我甚至尝试使用以下代码滚动到最后一个元素,但它不起作用
editTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
recyclerView.scrollToPosition(chatAdapter.getItemCount());
}
}
});
Run Code Online (Sandbox Code Playgroud)
我可以尝试adjustPan将平移向上移动,但它隐藏了我的工具栏.请提出任何解决问题的方法.
我正在从适配器中的演示者请求图像:
@Override
public void onBindViewHolder(SiteAdapter.ViewHolder holder, int position)
{
Site site = sites.get(position);
holder.siteName.setText(site.getName());
requestHolderLogo(holder, site.getLinks().getLogoUrl());
}
private void requestHolderLogo(final ViewHolder holder, final String logoUrl)
{
compositeSubscription.add(
presenter.bitmap(logoUrl)
.subscribe(
bitmap -> {
holder.siteLogo.setImageBitmap(bitmap);
holder.siteLogo.setVisibility(View.VISIBLE);
},
error -> {
holder.siteName.setVisibility(View.VISIBLE);
})
);
}
Run Code Online (Sandbox Code Playgroud)
我应该在ViewHolder重新使用时取消订阅.这很容易.
但是当视图被销毁时如何停止所有订阅?我也应该使演示者引用无效以避免内存泄漏
我想为我的RecyclerView实现搜索功能.在文本更改后,我想更改使用此小部件显示的数据.也许这个问题之前已被问过或很简单,但我不知道如何更改要显示的数据......
我的RecyclerView定义如下:
// 1. get a reference to recyclerView
mRecyclerView = (RecyclerView)findViewById(R.id.recyclerView);
// 2. set layoutManger
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// 3. create an adapter
mAdapter = new ItemsAdapter(itemsData);
// 4. set adapter
mRecyclerView.setAdapter(mAdapter);
Run Code Online (Sandbox Code Playgroud)
我展示的数据是这样的:
ItemData itemsData[] = { new ItemData("Mary Richards"),
new ItemData("Tom Brown"),
new ItemData("Lucy London")
};
Run Code Online (Sandbox Code Playgroud)
所以,当我想给适配器另一组数据,另一个数组(例如一个项目)时,我该怎么办?
有没有办法恢复滑动操作并在滑动完成后将视图固定器恢复到其初始位置并onSwiped在ItemTouchHelper.Callback实例上调用?我得到了RecyclerView,ItemTouchHelper并且ItemTouchHelper.Callback实例完美地协同工作,我只需要恢复滑动动作,而不是在某些情况下删除滑动项目.
我打算开发一个应用程序,在其中显示一些动态数据recyclerCardView.所以我决定
在我的主要内部添加一个recyclerView名字.这是我的应用程序的代码:CheckBoxRecyclerViewrecyclerView
我的主要活动:
setContentView(R.layout.activity_startup);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
reminderView = (RecyclerView) findViewById(R.id.reminder_recycler_view);
RlayoutManager = new LinearLayoutManager(this);
reminderView.setLayoutManager(RlayoutManager);
setSupportActionBar(toolbar);
cardView = (CardView) findViewById(R.id.card_first);
cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext() , ReminderActivity.class);
startActivity(intent);
}
});
ReminderHelper helper = new ReminderHelper(getApplicationContext());
ReminderAdapter reminderAdapter = new ReminderAdapter(helper);
ContentValues reminderValues = new ContentValues();
ContentValues checkboxValues = new ContentValues();
// Devlopment Part ->
reminderValues.put("reminderTitle" , "A Reminder Title");
reminderValues.put("reminderLastModDate" , 0); …Run Code Online (Sandbox Code Playgroud)