簡體   English   中英

TableLayout ScrollView垂直和水平

[英]TableLayout ScrollView Vertical & Horizontal

我們如何垂直和水平設置ScrollView 我嘗試了下面的代碼,但是沒有用。

<ScrollView
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:background="@color/red"
 android:scrollbarFadeDuration="1000"
 android:scrollbarSize="12dip" >

   <HorizontalScrollView
     android:id="@+id/horizontalScrollView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >

      <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:collapseColumns="2"
        android:stretchColumns="1" >
    </TableLayout>
</HorizontalScrollView>

<ScrollView >
</ScrollView>

這是我的所有代碼: http : //pastebin.com/ysRhLMyt

當前屏幕:

在此處輸入圖片說明

我想一直顯示滾動條。

嘗試,

  • 設置android:scrollbarFadeDuration =“ 0”

      OR 
  • ScrollView1.setScrollbarFadingEnabled(false);

      OR 
  • android:scrollbarFadeDuration =“ 0”

    android:scrollbarAlwaysDrawVerticalTrack =“ true”用於垂直

    android:scrollbarAlwaysDrawHorizo​​ntalTrack =“ true”用於水平

還有一件事情,

請記住,ScrollView只能有一個子控件,因此我們可以將一個容器(線性,相對,表布局)作為ScrollView的子控件,並將所有控件放入該子控件中。

供參考: http : //android-pro.blogspot.com/2010/02/android-scrollview.html

在下面的代碼可以進行水平和垂直滾動查看,要查看其效果,請先定義一個200x 200 dp左右的區域,然后將此代碼粘貼到其中。

視圖將水平和垂直滾動。

<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarSize="10dp"
android:scrollbars="vertical" >

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />
        </LinearLayout>
    </LinearLayout>
</HorizontalScrollView>

嵌套滾動視圖不起作用。 它與滾動視圖觸摸處理有關:頂級視圖始終消耗所有觸摸事件。 您必須編寫自己的自定義滾動視圖。

嘗試使用android:orientation屬性。 這可以用於水平或垂直: android:orientation="horizontal"android:orientation="vertical"

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:scrollbarFadeDuration="1000"
      android:scrollbarSize="12dip"
      android:background="@color/red" 
      android:orientation="horizontal">

      <TableLayout android:layout_width="match_parent"  
            android:layout_marginTop="10dp" 
            android:id="@+id/tableLayout1" 
            android:layout_height="wrap_content" 
            android:stretchColumns="1" 
            android:collapseColumns="2">
      </TableLayout>
</ScrollView>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM