Android - 如何创建 Excel 工作表类型布局?

标签 android android-recyclerview

我想创建一个 Excel 类型的布局,其中有无限的垂直滚动。水平列数固定,但它们应该是可滚动的。

enter image description here

我试过下面的代码

 <HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
<android.support.v7.widget.RecyclerView
        android:id="@+id/table_data_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</HorizontalScrollView>

如果我使用上面的代码,那么我可以垂直滚动,但列是不可滚动的。

即使在 xml 中为 Horizo​​ntalScrollViewRecyclerView 提供固定高度,列也不会滚动。

终于找到答案here ,建议扩展 RecyclerView 并动态计算高度。

 public class MySmartRecyclerView extends RecyclerView {

  public MySmartRecyclerView(Context context) {
    super(context);
  }

  public MySmartRecyclerView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public MySmartRecyclerView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  @Override
  public boolean canScrollHorizontally(int direction) {
    return false;
  }

  @Override
  public int getMinimumWidth() {
    return computedWidth;
  }

  @Override
  protected void onMeasure(int widthSpec, int heightSpec) {
    super.onMeasure(widthSpec, heightSpec);
    setMeasuredDimension(computedWidth, getMeasuredHeight());
  }

  @Override
  protected int getSuggestedMinimumWidth() {
    return computedWidth;
  }
}

那么只有这样才能实现吗?或者有没有其他方法可以实现这一目标。 ScrollView 中的 RecyclerView 有 NestedScrollView,但 Horizo​​ntalScrollView 没有这样的东西。

任何指针将不胜感激。 TIA。

最佳答案

还有一种替代解决方案。你可以用这个 library .

关于Android - 如何创建 Excel 工作表类型布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42397725/

相关文章:

android - 更改 android API 级别时出错?

android - Unity - 读取文本文件(Android 和网络播放器)

android - 如何在 androidx.recyclerview.widget 中使用 androidx.recyclerview.selection。或者如何在 android 中使用 kotlin 在 recyclerview 中选择一个项目?

android - 如何在Android Kotlin上增加动态布局?

android - 如何使回收器 View 滚动超过项目的高度

java - 在警报对话框中获取用户选择

android - 如何在 Android Studio 的屏幕截图中添加更多框架,如 Nexus 6P、5X 等

android - ListView回收切换seekbar位置

android - 仅从 recyclerview 显示的项目,而不是从 android 项目顶部显示的项目

java - 了解 AsyncTask 是否正在运行