Scrollview以横向模式隐藏textview文本

时间:2017-05-26 19:19:41

标签: android

我正在尝试使用scrollview使textview包含在其中可滚动。

我正在使用网格布局,并且能够根据需要定位项目,尤其是长文本块,包含在滚动视图中(大标题下的文本)。

然而,在旋转时,长文本块完全消失,我必须继续向上滚动以使其可见。在横向模式下,我需要它按预期显示。

Portrait mode- works ok

landscape mode, text not visible until swiped up

landscape mode, now visible after swiping up

text now visible after swiping up

这是我的XML

<?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>

谢谢

2 个答案:

答案 0 :(得分: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>

如果您的业务规则不允许整个布局可滚动,您可以做的是将ScrollView作为XML中的第一个布局,并将其他视图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>

答案 1 :(得分:0)

1。print str(i) + '\n' + str(j) 添加为RelativeLayout的直接子项并将ScrollView放入其中。

2。使用归因TextViewandroid:fillViewport="true"

试试这个:

ScrollView
相关问题