Android -- 如何允许水平和垂直滚动

标签 android graphics view scroll

有只允许垂直滚动的 ScrollView 和只允许水平滚动的 Horizo​​ntalScrollView,但两者都没有类。这似乎是 Android UI 中的一个巨大缺陷。有什么技巧可以做到这一点吗?

最佳答案

试试这个

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content">

    <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="wrap_content"
                  android:layout_height="fill_parent">

         <TableLayout
                  android:id="@+id/amortization"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content">

              <TableRow
                  android:background="#ffff00">
                  <TextView
                       android:text="@string/amortization_1"
                       android:padding="3dip"/>
                  <TextView
                       android:text="@string/amortization_2"
                       android:padding="3dip"/>
                  <TextView
                       android:text="@string/amortization_3"
                       android:padding="3dip"/>
                  <TextView
                       android:text="@string/amortization_4"
                       android:padding="3dip"/>
                  <TextView
                       android:text="@string/amortization_5"
                       android:padding="3dip"/>
                  <TextView
                       android:text="@string/amortization_6"
                       android:padding="3dip"/>
                  <TextView
                       android:text="@string/amortization_7"
                       android:padding="3dip"/> 
              </TableRow>
         </TableLayout>
    </HorizontalScrollView>
</ScrollView>

关于Android -- 如何允许水平和垂直滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5771455/

相关文章:

java - 针对 Android 11 (Api 30) 重命名视频/图像

android - 检查 View 在屏幕上是否可见

sql - 通过 PostgreSQL 数据库聚合大型(十亿行)数据集

mysql - 查看代码中出现错误 1064

Android 将颜色设置为 ListView 项

java - Firebase 数据库无法正常工作且无响应

macos - 以编程方式进行漂亮的像素级绘画

java - 将 Bitmap 或 ImageView 的宽度和高度设置为 CustomView

algorithm - 如何针对严格规定的多边形裁剪一条线

.net - WinForms图表控件自动滚动