如何将Layout.xml显示到RecyclerView中

时间:2019-01-07 21:09:10

标签: android-recyclerview

我正在使用recyclerview制作一个应用程序。我想通过单击cardView的每个项目时进行翻译,在RecyclerView上自上而下显示layout.xml。因此我将AnimationUtils.loadAnimationin放在RecyclerView.Adapter中。但是当单击itema时,应用程序崩溃了

这用于RecyclerView和android studio`:

这是我的适配器零件代码:

public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.MyViewHolder> {

  List<Banner> banners;
  Context context;
  View aview;

  LinearLayout hidden_panell;


  public ItemAdapter(List<Banner> banners,Context context){
    this.banners=banners;
    this.context=context;

  }



  @Override
  public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      aview = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_list_item, parent, false);
    return new MyViewHolder(aview);

  }





  @Override
  public void onBindViewHolder(final MyViewHolder holder, final int position) {
    Banner banner=banners.get(position);
    holder.aMassege.setText(banner.getName());



    holder.btnregis.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {


        Animation up = AnimationUtils.loadAnimation(context, R.anim.up);
        hidden_panell.startAnimation(up);
        hidden_panell.setVisibility(View.VISIBLE);

      }
    });

  }


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



  public class MyViewHolder extends RecyclerView.ViewHolder {
    public ImageView aAvatar;
    public TextView aName;
    public TextView aMassege;
    public TextView aTime;
    public LinearLayout aItem;
    public Button btnregis;


    public LinearLayout hidden_panell;



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

      hidden_panell = (LinearLayout) itemView.findViewById(R.id.hidden_panel);



      aAvatar = (ImageView) itemView.findViewById(R.id.img_avatar);
      aName = (TextView) itemView.findViewById(R.id.txt_name);
      aMassege = (TextView) itemView.findViewById(R.id.txt_masseg);
      aTime = (TextView) itemView.findViewById(R.id.txt_time);
      aItem = (LinearLayout) itemView.findViewById(R.id.item_layout);
      btnregis = (Button) itemView.findViewById(R.id.btnregis);

    }
  }
}

这是Mainactivity.xml部分:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  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:background="#2a3351"
  tools:context="com.et6u7g10.asus1.workerreport.WorkerActivity">



  <include layout="@layout/toolbar_main"/>
  <include layout="@layout/hidden_panel"/>
  <android.support.v7.widget.RecyclerView
  android:layout_marginLeft="5dip"
  android:layout_marginTop="50dip"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@+id/recycle_view2">
</android.support.v7.widget.RecyclerView>




</RelativeLayout>

0 个答案:

没有答案