2016-04-05 18 views
1

私は、いくつかの画像ビューを持つScrollViewを持っています。しかし、スクロールは非常に遅く、パフォーマンスが悪い理由は何か分かりません。スクロールを高速化するために何かする必要はありますか? またはこの問題の原因は何ですか?Android ScrollViewでスロースクロール

`

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

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

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

       <ImageView /> 

     <ImageView /> 

     <ImageView /> 

     <ImageView /> 

     <ImageView /> 

       <ImageView /> 

      </RelativeLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:gravity="center" 
       android:orientation="vertical"> 

       <Button /> 

      </LinearLayout> 
     </RelativeLayout> 
    </ScrollView> 
</RelativeLayout>` 
+0

不必要にネストされた 'RelativeLayout'に加えて、問題を引き起こすものはないようです。 「遅い」とは、それが文字通りゆっくりとスクロールすることを意味しますか、スクロールするとレンダリングに問題が生じるかどうかを意味しますか?あなたが読み込んでいる画像の大きさはどれくらいですか?大きな画像を読み込んでいる場合は、ファイルサイズを小さくしてみてください。 – Charlemagne

答えて

0

私は英語では非常に流暢ではないが、私はあなたにそれを説明しようとします!あなたはちょうどあなたが子ビュー内の複数の子ビューを使用すると、システム上でより多くの課税を持ってこの

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

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

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

      <ImageView /> 

    <ImageView /> 

    <ImageView /> 

    <ImageView /> 

    <ImageView /> 

      <ImageView /> 

     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:gravity="center" 
      android:orientation="vertical"> 

      <Button /> 

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

+0

ありがとう、私はそれを試してみます。 – Vera

+0

残念ながら、それは役に立たなかった。 – Vera

0

のような位置をscrollview変更しようとする必要が

、私はなぜ取得しないだろう親RelativeLayoutの中にRelativeLayoutを使用します。スニペットを投稿しただけですが、多くの子レイアウトが必要です。

あなたはそれが次のようになり、またはRelativeLayoutLinearLayoutを置き換える必要があり、よりhere

を見つけます。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="100dp" /> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="100dp" /> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="100dp" /> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="100dp" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="100dp" /> 
</LinearLayout> 

+0

すべてのRelativeLayoutsを削除しても、ScrollViewだけで、RelativeLayoutの内部にはまだ非常に遅いです。 – Vera

+0

なぜImageViewタグが空になっていますか – Mihai

+0

ImageView内のコードを例のためだけに削除しました。 – Vera

1

問題は、画像の大きさでした。 ScrollViewや複数のImageViewでパフォーマンスに問題がある場合は、画像のサイズに注意してください!私の場合、私はそれらを約に減らしました。各画像は20KB - 50KBです。