Android:滚动包含recyclerView的子视图时如何滚动父视图

问题描述:

我已经创建了一个应用程序,其中包含mainActivity内的viewPager,此viewPager包含5个片段,其中4个是recyclerViews,另一个是包含一些文本的正常linearLayout。 ..Android:滚动包含recyclerView的子视图时如何滚动父视图

这里是应用程序的截图,在tablayout并不是所有的标签都可见:

screenshot

现在,你可能已看到,没有太多的空间,在viewPager让用户看到任何东西,所以他们不得不滚动浏览recylerV中的东西IEW。我想修改我的应用程序,以便当用户尝试在recyclerView内滚动时,mainActivity的可见部分向下滚动,直到recyclerView占据整个页面,然后recyclerView开始正常滚动。

有人可以帮助我实现这种类型的滚动功能到我的应用程序。您可以查看this应用程序以了解我所说的内容。只要打开任何电影或电视系列,然后尝试滚动,mainActivity首先滚动,然后其余的布局....可以有人请帮助。我已经尝试了stackOverflow上的解决方案,其中许多都不起作用,我也尝试谷歌解决方案,但没有得到任何有用的东西....

这是我的适配器的代码:

public class cardViewAdapterCreditsCast extends RecyclerView.Adapter<cardViewAdapterCreditsCast.ViewHolder> { 

private Context context; 
private List<creditsModel> creditsModels; 

public cardViewAdapterCreditsCast(Context context, List<creditsModel> creditsModels) { 
    this.context = context; 
    this.creditsModels = creditsModels; 
} 

@Override 
public cardViewAdapterCreditsCast.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.new_cast_row, parent, false); 

    return new cardViewAdapterCreditsCast.ViewHolder(view); 
} 

@Override 
public void onBindViewHolder(cardViewAdapterCreditsCast.ViewHolder holder, int position) { 
    final creditsModel creditsModel = creditsModels.get(position); 

    int tempNumber = holder.celebImage.getWidth(); 
    holder.celebImage.setMinimumHeight(tempNumber); 
    holder.celebImage.setMaxHeight(tempNumber + 1); 

    String imagePath = "https://image.tmdb.org/t/p/w500" + creditsModel.getProfilePath(); 

    holder.starringAs.setText(creditsModel.getCharacter()); 
    holder.celebName.setText(creditsModel.getActorName()); 

    if (creditsModel.getProfilePath() != null) { 
     Picasso.with(context).load(imagePath).transform(new CircleTransform()).into(holder.celebImage); 
    } else 
     holder.celebImage.setBackgroundResource(R.drawable.not_found); 
} 

@Override 
public int getItemCount() { 
    return creditsModels.size(); 
} 

public class ViewHolder extends RecyclerView.ViewHolder { 

    public ImageView celebImage; 
    public TextView celebName; 
    public TextView starringAs; 

    private LinearLayout linearLayout; 

    public ViewHolder(View itemView) { 
     super(itemView); 

     linearLayout = (LinearLayout) itemView.findViewById(R.id.castRowMainLinearLayout); 

     celebImage = (ImageView) itemView.findViewById(R.id.castRowImage); 
     celebName = (TextView) itemView.findViewById(R.id.castRowName); 
     starringAs = (TextView) itemView.findViewById(R.id.castRowAppearance); 
     } 
    } 
} 
+0

您应该使用协调布局 - 看一看http://saulmm.github.io/mastering-coordinator –