2017-07-25 6 views
0

私はユーザがLinearLayoutの中に含まれているコンテンツを垂直方向にスクロールできるようにしたいと考えています。これはScrollViewの中にあります。ここでは、この活動のためのレイアウトXMLがどのようなものかをまとめている:私は見ています何LinearLayoutはScrollView内で切り詰めています。

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

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="20dip" 
      android:orientation="vertical"> 

      <!-- a bunch of standard widgets, omitted for brevity --> 

      <!-- everything renders but starting in this TextView --> 
      <!-- content begins to get truncated --> 
      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:paddingLeft="20dp" 
       android:gravity="left" 
       android:textSize="20dip"/> 

      <!-- this View, really just a trick for a horizontal row, is --> 
      <!-- completely cutoff --> 
      <View 
       android:layout_width="fill_parent" 
       android:layout_height="2dip" 
       android:layout_marginTop="10dp" 
       android:layout_marginBottom="10dp" 
       android:background="@color/green" /> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

は、内側LinearLayoutのコンテンツはScrollView内部カットオフされていることです。上記の最後のTextViewでは、テキストがほとんど含まれていない場合は、その下のViewが縦長にレンダリングされますが、横向きではレンダリングされません。このTextViewに多くのテキストが含まれている場合は、ポートレートモードでカットオフされます。

私はStack Overflowで見つけた推奨を試しました。 ScrollViewにボトムパッドを追加しても問題が解決されず、NestedScrollViewの場合はScrollViewをスワップしませんでした。

ご意見をお待ちしております。これは実際にブロッカーになっています。

+0

スクリーンショットを追加 –

+0

@OussemaAroua絶対に必要でない限り、スクリーンショットを共有したくないです。なぜそれが助けになると思いますか?基本的には、質問の中で私が何を記述したかを知ることができますが、底にあるものは途切れています。あなたが見ることができない私のレイアウトの欠陥を見ることができればと思っています。 –

+0

内部ビューの高さのいくつかをmatch_parentに設定してみてください。たとえば、LinearLayoutの – stan0

答えて

6

LinearLayoutの余白をパディングに変更します。または、本当にマージンにする必要がある場合(おそらくカスタム背景を使用している)、LinearLayoutFrameLayoutにラップします。

は、LinearLayoutからその高さを取っています(正確には、スクロール可能な範囲を計算しています)。この値には余白が含まれないため、ScrollViewLinearLayoutの上下の余白の合計で「短すぎます」となります。測定中

+0

つまり、 'ScrollView'には高さがあまりにも小さく割り当てられ、' LinearLayout'を実際に見る時間が来たら、それは短く止まり、上下のマージンの合計を切り捨てます。私のケースは40dpでした。 –

+0

私はそれがCSSボックスモデルほど簡単だと信じています。パディングはビューの寸法の一部であり、余白はありません。 'ScrollView.canScroll()'をチェックしてください... 'ScrollView'の高さを最初の子の高さと比較します。 –

+0

助けてくれてありがとう、私の一日を作った。私はこれで何も見つかりませんでしたので、驚いています...多分私は間違ったことを探していました。うまくいけばあなたの答えは別の疲れたAndroid開発者を助けることができます:-) –

0

マージンは無視され、あなたはあなたのScrollViewにパディングを提供することができ、また、あなたのLinearLayout

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

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="20dp"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <!-- a bunch of standard widgets, omitted for brevity --> 

     <!-- everything renders but starting in this TextView --> 
     <!-- content begins to get truncated --> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="20dp" 
      android:gravity="left" 
      android:textSize="20dip"/> 

     <!-- this View, really just a trick for a horizontal row, is --> 
     <!-- completely cutoff --> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="2dip" 
      android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" 
      android:background="@color/green" /> 
    </LinearLayout> 
</ScrollView> 

からfill_parentを余白を削除this

を参照してください非推奨とmatch_parentと改名されましたAPIレベル8以上

+1

スクロールビューでのパディングの使用には、必ずしも望ましくないとは限らない結果があります。最初は、コンテンツがパディングによってクリップされることです(これは 'android:clipToPadding =" false "'で修正できます)。もう1つ(どのように修正するかわからない)は、スクロールバーがパディングの内側にあることです。 –

+0

はい、私はスクロールバーがパディングの内側にあることに同意します。これを指摘してくれてありがとう –

関連する問題