2016-07-07 10 views
1

ScrollViewと苦労しています。なぜ表示されるテキストがあっても、ScrollViewがスクロールしない

- 私の目的は、画像とテキスト(各画像の下)でスクロール可能なフラグメントを作ることです。私はすでにいくつかのシンプルな画像を追加しており、これらの画像の下に専用のScrollViewをテキスト用に追加しようとしていました。

問題の説明はここから: フラグメントが1枚のだけの画像があり、1はScrollViewはScrollViewが正常に動作しますが、私は以下の1枚の以上の画像を追加するとき、ScrollViewだけでフリーズするともうスクロールしません。私のミスはどこですか?ここで

コードされています

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:fillViewport="true"> 
<LinearLayout 
    android:id="@+id/LinearLayout_Parent" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <ImageView 
     android:id="@+id/top_image1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/image1" 
     android:adjustViewBounds="true"/> 
     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="100dp"> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/rly_large"/> 
     </ScrollView> 
    //when ImageView is added ScrollView stops wotking 
    **<ImageView 
     android:id="@+id/top_image2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/image2"/>** 
</LinearLayout> 

Whitout ImageViewのすべて**内部が正常に動作しますが、そのImageViewのが追加されたときにScrollViewスクロールを停止します。

私はあなたが間違いを指摘してくれることを願っており、希望はばかな質問をしませんでした。

ありがとうございました。

アンドロイドStuido:良い習慣ではありませんScrollViewScrollView別の内側に持っ2.1.2 JRE 1.8.0-B15

+0

なぜScrollViewを 'ScrollView'の内部で使用していますか?その良いプログラミングではありません。 – user392117

+0

NestedScrollView https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.htmlを試してみてください。ルートScrollViewのサウンドにwrap_contentを使用すると音が鳴ります。 –

+0

希望する出力の画像ファイルを投稿します。 –

答えて

0

。しかし、あなたが使用したコードは、場合によっては動作する可能性があります。しかし、複数の要素を持っていると失敗することがあります。その場合、gestureを特定できないことがあります。

ただし、この回答が役に立たない場合は、ScrollView Inside ScrollViewをお試しください。子のタッチが識別されると、親のScrollView'sが無効になります。助けがあればpostも見てください。

+0

ありがとうございます、お時間をいただき、私はそれらの上で実装しようとし、それが動作するかどうかを確認します。ありがとうございました。 –

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

<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:fillViewport="true"> 
<LinearLayout 
    android:id="@+id/LinearLayout_Parent" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <ImageView 
     android:id="@+id/top_image1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/image1" 
     android:adjustViewBounds="true"/> 
     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="100dp"> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/rly_large"/> 
     </ScrollView> 

    <ImageView 
     android:id="@+id/top_image2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/image2"/> 
</LinearLayout> 

あなたは、ルート要素としてScrollViewを使ってますが近いのタグを追加することはありません。

また、ScrollViewをルート要素として使用すると、私の経験上問題が発生します。現在、ルート要素の1つであるScrollViewを押し込んで、ルート要素としてLinearLayoutを設定すると、あなたの問題を解決するかもしれない。

さらに:すべてが正常に動作しますが、そのImageViewのが追加されたときにScrollViewは、スクロールを停止**内Whitout ImageViewの

は少しわかりにくいです。どちらがスクロールを停止しますか?

+0

私の悪い、スクロールを停止するものは、ImageViewの下にあるものです。 –

+0

スクロールする必要はありますか?テキストがイメージのすぐ下に収まるのに十分短いか、それともスクロールが必要なのですか? – Zoe

+0

テキストは長いので、大きなテキストボックスより小さなスクロールボックスを持つ方がよいと思っています。 –

関連する問題