使用网格布局管理器作为子级的可扩展RecyclerView

时间:2015-09-17 20:09:19

标签: gridview android-recyclerview expandable recyclerview-layout

我希望有一个可折叠的RecyclerView,就像可扩展的ListView一样,每个paren的子节点都会呈现一个GridView布局管理器。

有可能吗?任何人都可以指导我如何做到这一点? 感谢

3 个答案:

答案 0 :(得分:2)

如何使用此here实现可扩展GridView的完整示例library

基本上,您使用库将项目分组为多个部分,以便为每个部分设置标题,但您可以实现它yourself

然后添加public class MainActivity extends Activity { @SuppressWarnings("unused") private ViewFlipper mViewFlipper; private GestureDetector mGestureDetector; int[] resources = { R.drawable.t1, R.drawable.t2, R.drawable.t3, R.drawable.t4, R.drawable.t5 }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the ViewFlipper mViewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper); //Automatically Start Flipping mViewFlipper.setAutoStart(true); mViewFlipper.setFlipInterval(5000); // for 5 sec // Add all the images to the ViewFlipper for (int i = 0; i < resources.length; i++) { ImageView imageView = new ImageView(this); imageView.setPadding(40, 80, 40, 80); imageView.setImageResource(resources[i]); mViewFlipper.addView(imageView); // Set in/out flipping animations mViewFlipper.setInAnimation(this, android.R.anim.fade_in); mViewFlipper.setOutAnimation(this, android.R.anim.fade_out); OnGestureListener customGestureDetector = new CustomGestureDetector(); mGestureDetector = new GestureDetector(MainActivity.this, customGestureDetector); }} class CustomGestureDetector extends GestureDetector.SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // Swipe left (next) if (e1.getX() > e2.getX()) { mViewFlipper.setInAnimation(MainActivity.this, R.anim.left_in); mViewFlipper.setOutAnimation(MainActivity.this, R.anim.left_out); mViewFlipper.showNext(); } // Swipe right (previous) if (e1.getX() < e2.getX()) { mViewFlipper.setInAnimation(MainActivity.this, R.anim.right_in); mViewFlipper.setOutAnimation(MainActivity.this, R.anim.right_out); mViewFlipper.showPrevious(); } return super.onFling(e1, e2, velocityX, velocityY); } } @Override public boolean onTouchEvent(MotionEvent event) { mGestureDetector.onTouchEvent(event); return super.onTouchEvent(event); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ,定义每行的列数(本例中为2),并将标题设置为每行2个列的跨度大小,子节点的跨度大小为1列行:

GridLayoutManager

要展开/展开各个部分,请检查example GridLayoutManager glm = new GridLayoutManager(getContext(), 2); glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch(sectionAdapter.getSectionItemViewType(position)) { case SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER: return 2; default: return 1; } } }); recyclerView.setLayoutManager(glm); 变量的使用情况。

答案 1 :(得分:1)

您可以使用此example of Expandable RecyclerView。它提供了一个可扩展的RecyclerView,其中包含可以单独扩展以在二维滚动网格中显示其子项的组项。可以选择每个网格项。

这是如何工作的:每个ChildViewHolder对象从RecyclerView适配器接收数据数组以显示在网格行中。然后它在相同大小的矩形单元格中分解其行的布局。每个单元格显示一段数据。

希望这会帮助任何寻找此事的人。

答案 2 :(得分:0)

您可以使用Import-Module BEMCLI #BackupExec $Array = @() $object= @{} #For each last 15 job backups ForEach ($i in $(Get-BEJob "FULL" | Get-BEJobHistory -FromStartTime (Get-Date).AddDays("-15") -JobType Backup)) { $object.TAPE= ($i | Get-BEJobLog | Get-BEJobLogFiles) # get Tape $object.START_TIME=$i.StartTime #get starttime $object.END_TIME=$i.EndTime #get endtime $Array += $Object } $Array | ft 和儿童视图使用其他Expandable RecyclerVewRecyclerView

https://github.com/bignerdranch/expandable-recycler-view