带有RecyclerView的TableLayout

RecyclerView只有两个布局pipe理器: LinearLayoutManagerGridLayoutManager 。 有没有办法使用TableLayout作为与RecyclerView布局pipe理器? 任何build议?

编辑:我不知道是否有任何解决scheme没有从零编写布局pipe理器。 TableLayout行为对我来说已经足够了,只是想要在处理大量的fo数据时添加回收function来处理性能问题。

而创build一个表看看listview是不是解决我的问题我想,因为我的表是非常dynamic的,我甚至不知道列名,客户决定表的所有细节。 所以单元格是自定义的,列宽度需要根据内容长度自动resize。 我不认为listview可以处理。

预先感谢帮助。

Solutions Collecting From Web of "带有RecyclerView的TableLayout"

看看这个库 。 看来这正是你所需要的。 它也有一个回收系统。

您可以使用Android RecyclerView和GridView GridLayoutManager示例教程

http://www.android-examples.com/android-recyclerview-with-gridview-gridlayoutmanager/

使用GridView GridLayoutManager示例教程的Android RecyclerView。

MainActivity.java文件的代码。

 package com.android_examples.recyclerviewgridview_android_examplescom; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; Context context; RecyclerView.Adapter recyclerView_Adapter; RecyclerView.LayoutManager recyclerViewLayoutManager; String[] numbers = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); context = getApplicationContext(); recyclerView = (RecyclerView) findViewById(R.id.recycler_view1); //Change 2 to your choice because here 2 is the number of Grid layout Columns in each row. recyclerViewLayoutManager = new GridLayoutManager(context, 2); recyclerView.setLayoutManager(recyclerViewLayoutManager); recyclerView_Adapter = new RecyclerViewAdapter(context,numbers); recyclerView.setAdapter(recyclerView_Adapter); } } 

activity_main.xml布局文件的代码。

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.android_examples.recyclerviewgridview_android_examplescom.MainActivity" android:id="@+id/relativelayout"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view1" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" > </android.support.v7.widget.RecyclerView> </RelativeLayout> 

RecyclerViewAdapter.java文件的代码。

 package com.android_examples.recyclerviewgridview_android_examplescom; import android.content.Context; import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; /** * Created by JUNED on 6/16/2016. */ public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>{ String[] values; Context context1; public RecyclerViewAdapter(Context context2,String[] values2){ values = values2; context1 = context2; } public static class ViewHolder extends RecyclerView.ViewHolder{ public TextView textView; public ViewHolder(View v){ super(v); textView = (TextView) v.findViewById(R.id.textview1); } } @Override public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){ View view1 = LayoutInflater.from(context1).inflate(R.layout.recycler_view_items,parent,false); ViewHolder viewHolder1 = new ViewHolder(view1); return viewHolder1; } @Override public void onBindViewHolder(ViewHolder Vholder, int position){ Vholder.textView.setText(values[position]); Vholder.textView.setBackgroundColor(Color.CYAN); Vholder.textView.setTextColor(Color.BLUE); } @Override public int getItemCount(){ return values.length; } } 

recycler_view_items.xml布局文件的代码。

 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/cardview1" android:layout_width="match_parent" android:layout_height="wrap_content" card_view:cardElevation="7dp" card_view:contentPadding="7dp" card_view:cardCornerRadius="7dp" card_view:cardMaxElevation="7dp" > <TextView android:id="@+id/textview1" android:layout_width="match_parent" android:layout_height="match_parent" android:textSize="20dp" android:textStyle="bold" android:padding="10dp" android:layout_gravity="center" android:gravity="center" /> </android.support.v7.widget.CardView> 

http://www.android-examples.com/android-recyclerview-with-gridview-gridlayoutmanager/

或遵循简单的表格布局android表格布局 – 简单的例子

使用linearlayout创build一个自定义行,然后将该行附加到recyclerView适配器,这只是在RecyclerView中制作一个类似Structure的表的解决scheme。