2017-05-26 6 views
0

私はscrollviewを使用して、その中にラップされたtextviewをスクロール可能にしようとしています。Scrollviewランドスケープモードでtextviewテキストを隠す

私は、グリッドレイアウトを使用して、私がする必要があるとして、スクロールビュー(大見出しの下のテキスト)に包まれ、特に長いテキストブロックを、アイテムを配置することができていています。

はしかし、回転時に、長いテキストブロックは完全に消え、私はそれが見えるように、それを上にスクロール維持する必要があります。ランドスケープモードでは、予想どおりに表示する必要があります。これは私のXMLである

landscape mode, now visible after swiping up

text now visible after swiping up

Portrait mode- works ok

landscape mode, text not visible until swiped up

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include layout="@layout/toolbar" android:id="@+id/toolbar"/> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="centerCrop" 
     android:adjustViewBounds="true" 
     android:layout_marginTop="20dp" 
     android:id="@+id/articlesummaryimageview" 
     android:layout_below="@id/toolbar" 
     android:layout_centerHorizontal="true"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/articlesummaryheadingtextview" 
     android:layout_below="@id/articlesummaryimageview" 
     android:layout_centerHorizontal="true" 
     android:textSize="26dp" 
     android:textStyle="bold" 
     android:textAlignment="center" 
     android:layout_marginTop="20dp" 
     /> 


    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:id="@+id/articlesummaryscreenscrollview" 
     android:layout_below="@id/articlesummaryheadingtextview" 
     android:fillViewport="false" 
     android:layout_above="@+id/showfullarticlebutton" 
     > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/articlesummarytextview" 
      android:textSize="18dp" 
      android:textAlignment="center" 
      android:padding="5dp" 
      /> 
    </ScrollView> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/showfullarticlebutton" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:textSize="18dp" 
     android:text="Full Article" 

     style="@style/AlertDialog.AppCompat.Light" 
     /> 
</RelativeLayout> 

あなたが

答えて

0

ScrollViewの直接の子としてRelativeLayoutを追加し、その中TextViewを入れていただきありがとうございます。

attributge android:fillViewport="true"~ScrollViewを使用してください。

これを試してください:あなたはあなたの全体のレイアウトをスクロール可能か異なるデザインを思い付くする必要があるとしている

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include layout="@layout/toolbar" android:id="@+id/toolbar"/> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="centerCrop" 
     android:adjustViewBounds="true" 
     android:layout_marginTop="20dp" 
     android:id="@+id/articlesummaryimageview" 
     android:layout_below="@id/toolbar" 
     android:layout_centerHorizontal="true"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/articlesummaryheadingtextview" 
     android:layout_below="@id/articlesummaryimageview" 
     android:layout_centerHorizontal="true" 
     android:textSize="26dp" 
     android:textStyle="bold" 
     android:textAlignment="center" 
     android:layout_marginTop="20dp" /> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/articlesummaryscreenscrollview" 
     android:layout_below="@id/articlesummaryheadingtextview" 
     android:fillViewport="true" 
     android:layout_above="@+id/showfullarticlebutton"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/articlesummarytextview" 
       android:textSize="18dp" 
       android:textAlignment="center" 
       android:padding="5dp" 
       android:text="this is a text"/> 

     </RelativeLayout> 
    </ScrollView> 
    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/showfullarticlebutton" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:textSize="18dp" 
     android:text="Full Article" 
     style="@style/AlertDialog.AppCompat.Light" /> 
</RelativeLayout> 
2

。レイアウト全体をスクロール可能にするには、RelativeLayoutをScrollViewの内側に置き、ScrollViewのlayout_heightをwrap_contentに設定します。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/articlesummaryscreenscrollview" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:fillViewport="true" 
> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 

<include 
    layout="@layout/toolbar" 
    android:id="@+id/toolbar" 
    /> 

<ImageView 
    android:id="@+id/articlesummaryimageview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/toolbar" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="20dp" 
    android:adjustViewBounds="true" 
    android:scaleType="centerCrop" 
    /> 

<TextView 
    android:id="@+id/articlesummaryheadingtextview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/articlesummaryimageview" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="20dp" 
    android:textAlignment="center" 
    android:textSize="26dp" 
    android:textStyle="bold" 
    /> 

<TextView 
    android:id="@+id/articlesummarytextview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="5dp" 
    android:textAlignment="center" 
    android:textSize="18dp" 
    android:layout_above="@+id/showfullarticlebutton" 
    android:layout_below="@id/articlesummaryheadingtextview" 
    /> 

<Button 
    android:id="@+id/showfullarticlebutton" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:text="Full Article" 
    android:textSize="18dp" 
    style="@style/AlertDialog.AppCompat.Light" 
    /> 
</RelativeLayout> 

ビジネスルールをスクロールする全体のレイアウトを可能にしていない場合は、何を行うことができますことは、XMLの最初のレイアウトとしてごScrollViewを入れて、layout_aboveとlayout_belowあなたの他のビューを調整していますその最初のものに(基本的には常に表示され、それ以外のものはすべて周囲に調整されます)。

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <ScrollView 
     android:id="@+id/articlesummaryscreenscrollview" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_above="@+id/showfullarticlebutton" 
     android:fillViewport="false" 
     > 
    <TextView 
     android:id="@+id/articlesummarytextview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dp" 
     android:textAlignment="center" 
     android:textSize="18dp" 
     /> 
    </ScrollView> 
    <TextView 
     android:id="@+id/articlesummaryheadingtextview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/articlesummaryscreenscrollview" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:textAlignment="center" 
     android:textSize="26dp" 
     android:textStyle="bold" 
     /> 
    <ImageView 
     android:id="@+id/articlesummaryimageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/articlesummaryheadingtextview" 
     android:layout_below="@id/toolbar" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="20dp" 
     android:adjustViewBounds="true" 
     android:scaleType="centerCrop" 
     /> 
    <Button 
     android:id="@+id/showfullarticlebutton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="Full Article" 
     android:textSize="18dp" 
     style="@style/AlertDialog.AppCompat.Light" 
     /> 
    </RelativeLayout> 
関連する問題