我有一个Recyclerview显示水平项目列表。我正在显示一个标题和描述的文章列表:
mRecyclerView = findViewById(R.id.rvmain);
mRecyclerView.setOnFlingListener(null);
SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(mRecyclerView);
mLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new MainActivityRVAdapter(postsModels,MainActivity.this);
mRecyclerView.setAdapter(mAdapter);
在我的菜单中,我有两个单击点击的项目,我想更改显示的特定回收者视图的字体大小
<item
android:id="@+id/fontincrease"
android:title="@string/fontincrease"
app:showAsAction="always"
/>
<item
android:id="@+id/fontdecrease"
android:title="@string/fontdecrease"
app:showAsAction="always"
/>
现在如何从这里处理我无法理解
我知道增加字体大小的代码:
float size = mViewShabad.getTextSize()*1.1f;
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
我必须获取视图并增加描述的字体。
我用Google搜索,并使用以下行来访问视图中的元素。
int position = ((LinearLayoutManager)mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
(TextView) mRecyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.title)
我可以更改字体大小,但我想在滚动
时重置它我在尝试:
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
{
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
// what to do here so that everything is shown the default way
}
});
答案 0 :(得分:0)
int currentPos = -1;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if(currentPos != -1){
// change the font of view holder at current pos (which is 2)
currentPos = -1;
}
}