Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 滚动视图在横向模式下隐藏文本视图文本_Android - Fatal编程技术网

Android 滚动视图在横向模式下隐藏文本视图文本

Android 滚动视图在横向模式下隐藏文本视图文本,android,Android,我试图使用scrollview使包装在其中的textview可滚动 我使用的是网格布局,能够根据需要定位项目,特别是长文本块,以滚动视图(大标题下的文本)包装 但是,在旋转时,长文本块完全消失,我必须不断向上滚动以使其可见。在横向模式下,我需要它像预期的那样可见 这是我的XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/

我试图使用scrollview使包装在其中的textview可滚动

我使用的是网格布局,能够根据需要定位项目,特别是长文本块,以滚动视图(大标题下的文本)包装

但是,在旋转时,长文本块完全消失,我必须不断向上滚动以使其可见。在横向模式下,我需要它像预期的那样可见

这是我的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>


谢谢您

1.添加
相对视图
作为
滚动视图
的直接子项,并将
文本视图
放入其中

2.使用attributege
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>

1.添加
相对视图
作为
滚动视图
的直接子项,并将
文本视图
放入其中

2.使用attributege
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>

您必须使整个布局可滚动,或者提出不同的设计。要使整个布局可滚动,请将RelativeLayout放在ScrollView中,并将ScrollView的布局高度设置为wrap内容

<?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_调整为初始布局(基本上使始终显示的视图和周围的所有其他视图都调整)


您必须使整个布局可滚动,或者提出不同的设计。要使整个布局可滚动,请将RelativeLayout放在ScrollView中,并将ScrollView的布局高度设置为wrap内容

<?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_调整为初始布局(基本上使始终显示的视图和周围的所有其他视图都调整)