Android — How to allow horizontal and vertical scrolling

前端 未结 3 841
粉色の甜心
粉色の甜心 2020-12-01 19:00

There is the ScrollView that allows only vertical scrolling, and the HorizontalScrollView that allows only horizontal scrolling, but no class for both. This seems like a pre

相关标签:
3条回答
  • 2020-12-01 19:07

    An example with an ImageView:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView android:id="@+id/ScrollView02" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                xmlns:android="http://schemas.android.com/apk/res/android">
    <HorizontalScrollView android:id="@+id/HorizontalScrollView01" 
                          android:layout_width="wrap_content" 
                          android:layout_height="wrap_content">
    <ImageView android:id="@+id/ImageView01"
               android:src="@drawable/pic" 
               android:isScrollContainer="true" 
               android:layout_height="fill_parent" 
               android:layout_width="fill_parent" 
               android:adjustViewBounds="true">
    </ImageView>
    </HorizontalScrollView>
    </ScrollView>
    

    Source: http://www.android-spa.com/viewtopic.php?t=3959&highlight=scrollview+vertical+horizontal

    0 讨论(0)
  • 2020-12-01 19:11

    I found it is important to set fillViewportbecause otherwise scroll bars might appear at random positions instead of at the right/bottom of the scrolling area:

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >
        <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true" >
        </HorizontalScrollView>
    </ScrollView>
    
    0 讨论(0)
  • 2020-12-01 19:23

    Try this

    <?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>
    
    0 讨论(0)
提交回复
热议问题