【发布时间】:2020-03-17 18:19:51
【问题描述】:
下面是 TabLayout 的 XML 代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.bapji.cubeon.FirstFragment"
android:id="@+id/first"
android:orientation="vertical"
android:background="@color/any">
<!-- TODO: Update blank fragment layout -->
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentBottom="true"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="@color/any"
app:tabSelectedTextColor="@color/white"
app:tabTextColor="@color/white"
app:tabIndicatorColor="@color/white"
android:layout_above="@+id/container"
>
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/any"
android:layout_weight="1"
>
</android.support.v4.view.ViewPager>
</LinearLayout>
下面是 RecyclerView 的 XML 代码
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/solve_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
在这里,我无法在 TabLayout 中滚动此 RecyclerView,我只能获得该 RecyclerView 的固定项目和我无法看到的其余项目,因此如果有人可以帮助我解决此问题,将对我有所帮助。
编辑 - 问题的屏幕截图
下面是 FragmentPagerAdapter 的代码
public class SectionPageAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public void addFragment(Fragment fragment, String title){
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
public SectionPageAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
}
RecyclerViewAdapter java 代码
public class SolveAdapter extends RecyclerView.Adapter<SolveAdapter.SolveViewHolder> {
Context context;
List<EachTime> mSolves;
public SolveAdapter(Context context, List<EachTime> mSolves) {
this.context = context;
this.mSolves = mSolves;
}
@Nullable
@Override
public SolveViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View layout;
layout = LayoutInflater.from(context).inflate(R.layout.fragment_each_time,parent,false);
return new SolveViewHolder(layout);
}
@Override
public void onBindViewHolder(SolveViewHolder holder, int position) {
holder.eachSolveTime.setText(mSolves.get(position).getCount());
holder.eachSolveScramble.setText(mSolves.get(position).getScramble());
holder.eachSolveDate.setText(mSolves.get(position).getDate());
}
@Override
public int getItemCount() {
return mSolves.size();
}
public class SolveViewHolder extends RecyclerView.ViewHolder{
TextView eachSolveTime,eachSolveDate,eachSolveScramble;
public SolveViewHolder(View itemView) {
super(itemView);
eachSolveDate = itemView.findViewById(R.id.each_solve_date);
eachSolveScramble = itemView.findViewById(R.id.each_solve_scramble);
eachSolveTime = itemView.findViewById(R.id.each_solve_title);
}
}
}
【问题讨论】:
标签: android android-recyclerview android-tablayout