2013-02-11 13 views
15

ScrollViewを適切にスクロールさせることはできません。これは、通常のLinearLayoutの場合と同様に、常に下部のコンテンツを切り捨てます。もちろんScrollViewはまったくスクロールしません

私のコード

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" > 

    <LinearLayout android:id="@+id/scroll_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:isScrollContainer="true" 
     android:orientation="vertical" > 

、私はすでに「fillViewport」と「isScrollContainer」プロパティを追加/削除することを試み、それがすべてでは何も変化しませんでした。

ありがとうございます。

+0

は、あなたが完全なXMLを貼り付けてくださいすることができます

のようなものを追加します。 – PaNaVTEC

+0

'android:layout_height =" match_parent "を' android:layout_height = "0dp" 'に変更し、' android:layout_weight = "1" 'を' ScrollView'に追加してみてください。 –

+0

ちょうど試して、運がない。 – thomaus

答えて

19

回答:XMLレイアウトのルート要素として使用するとScrollViewは機能しません。 LinearLayoutの中にラップする必要があります。その後、

ソリューション:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ScrollView android:id="@+id/scroll_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true" > 

     <LinearLayout android:id="@+id/scroll_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 
+47

これは私のためには機能しません... – Ciprian

+0

本当ですか? –

+1

+1本当にありがとうございました。 –

2

android:isScrollContainerLinearLayoutに削除します。ドキュメントのとおり、android:isScrollContainerは、ビューをスクロール可能に設定するために使用されます。それがあなたを助けることを願っていますこの定義についてはlinkを参照してください。

2

Androidのメーカーは、そのテンプレートの一部のアクティビティファイル(例えばマスター・ディテール)にNestedScrollViewを追加します。フラグメントファイルにScrollViewを、フラグメントのアクティビティファイルにScrollViewを置くと、スクロールビューが機能しなくなります。私のフラグメントファイル内のScrollViewを削除し、そのファイルをアクティビティファイルに残すことで、私の問題が解決されました。

0

ポストディレイメソッドを使用してスクロールを遅らせてください。これは私のために働いた

fragment_test.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rootRelativeLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:fresco="http://schemas.android.com/apk/res-auto"> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="40dp" 
     android:fillViewport="true" 
     android:scrollbars="none"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      ... 
     </RelativeLayout> 

    </ScrollView> 

</RelativeLayout> 

TestFragment.java

... 
private ScrollView mScrollView; 
... 
mScrollView = (ScrollView) mView.findViewById(R.id.scrollView); 
mScrollView.setSmoothScrollingEnabled(true); 
... 
new Handler().postDelayed(new Runnable() { 
    @Override 
    public void run() { 
     if(isAdded()) { 
      // Scroll 1000px down 
      mScrollView.smoothScrollTo(0, 1000); 
     } 
    } 
}, 150); 

、このことができます願っています。

0

これは私の問題を修正:私はのLinearLayoutにandroid:isScrollContainer="true"を追加し、前にScrollView コードを削除しました:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<ScrollView 
    android:id="@+id/scrollViewRecords" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:id="@+id/sheepList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

    </LinearLayout> 
</ScrollView> 
</LinearLayout> 

コードを

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:isScrollContainer="true"> 

    <LinearLayout 
     android:id="@+id/sheepList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

    </LinearLayout> 
</LinearLayout> 
0

した後は、これを閉じるする方法はあります質問?古いものであり、現在有効とマークされた回答には意味がありません。現在のところ、ScrollViewに関する唯一の有効なものは次のとおりです。

内に配置されたビュー階層をスクロールできるビューグループです。 スクロールビューに直接子供が1人しか置かれていない可能性があります。スクロール・ビュー内に複数のビューを追加するには、ビュー・グループを追加する直接の子(LinearLayoutなど)を作成し、そのLinearLayout内に追加のビューを配置します。 RecyclerViewまたはListViewをスクロールビューに追加しないでください。そうすると、ユーザーインターフェイスのパフォーマンスが低下し、ユーザーエクスペリエンスが低下します。

は、公式ドキュメントから撮影:https://developer.android.com/reference/android/widget/ScrollView.html

0

選択答えが正しくありません!

ScrollViewをルートビューとして使用することができます。パディングがないため、ScrollViewは機能しません。多分あなたのLinearLayoutに関連する何かがある、

android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
関連する問題