Как прокрутить таблицу в горизонтальном и вертикальном направлениях в андроиде
Я полностью запутался в прокрутке таблицы. Я должен реализовать таблицу с горизонтальной и вертикальной прокруткой. Я также видел пример заголовка таблицы, но в примере tablefixheader использовался адаптер для установки данных, но мне нужен метод add-view в макете таблицы. Я использовал ниже код, но он не мог поддерживать оба режима прокрутки
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fadeScrollbars="false">
<TableLayout
android:id="@+id/tableLayoutId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
</ScrollView>
Ответы
Ответ 1
Вот как я его реализовал и работает для меня:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/layout"
android:layout_height="match_parent"
android:scrollbars="horizontal|vertical"
android:layout_width="match_parent"
android:layout_marginTop="5dip"
android:scrollbarStyle="outsideInset"
android:fillViewport="true">
<HorizontalScrollView
android:id="@+id/horizontalView"
android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical"
android:layout_width="wrap_content"
android:layout_marginTop="5dip">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tlGridTable" >
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
Взгляните на этот код и посмотрите, помогает ли это.
Ответ 2
добавить как это
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_pins"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="horizontal" />
</HorizontalScrollView>
</ScrollView>