Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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_Xml_Scrollview - Fatal编程技术网

Android 我的滚动视图没有';卷轴

Android 我的滚动视图没有';卷轴,android,xml,scrollview,Android,Xml,Scrollview,我有一个这样的xml视图,正如您所看到的,我在其中有滚动视图,但滚动视图不滚动,只匹配屏幕大小,而且我无法看到屏幕下的数据。 这是我的代码: 代码已更新 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

我有一个这样的xml视图,正如您所看到的,我在其中有滚动视图,但滚动视图不滚动,只匹配屏幕大小,而且我无法看到屏幕下的数据。 这是我的代码: 代码已更新

 <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/aboveRelative"
        android:background="@color/darkOrange">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/category_text"
            android:textSize="23sp"
            android:textColor="@color/white"
            android:text="Category"
            android:paddingLeft="10sp" />
        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/gridview"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:verticalSpacing="0dp"
            android:horizontalSpacing="10dp"
            android:numColumns="2"
            />


    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/gray"
        android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/topVoices"
                android:textSize="23sp"
                android:text="@string/topVoices"

                android:paddingLeft="10sp" />

            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/trendlist"
                android:elevation="2dp"
                android:background="@color/white"
                android:layout_margin="10dp" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/moreTrend"
                android:layout_gravity="right"
                android:textSize="23sp"
                android:text="More"

                android:paddingLeft="10sp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"


                android:id="@+id/newVoices"
                android:textSize="23sp"
                android:text="@string/newVoices"
                android:paddingLeft="10sp" />
            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/soundlist"
                android:background="@color/white"
                android:layout_below="@+id/newVoices"
                android:elevation="5dp"
                android:layout_margin="10dp" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/soundlist"
                android:id="@+id/moreNew"
                android:layout_gravity="right"
                android:textSize="23sp"

                android:text="@string/more"/>
            <LinearLayout
                android:id="@+id/yoursongs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_gravity="center"
                android:background="@color/white"
                android:padding="10dp">

            </LinearLayout>

    </LinearLayout>

    </LinearLayout>


我确信屏幕下有一些数据,但scroll view不允许我滚动并查看它们。

您的布局错误。你要做的是:

  • 将ScrollView
    layout\u height
    属性更改为
    match\u parent

    ScrollView将占据整个屏幕并使其自身可滚动,这就是为什么您需要它作为match_父项。滚动发生在视图内部
  • 将滚动视图中的所有内容放在
    线性
    相对视图中
    。(见下文)
    滚动视图扩展了FrameLayout,因此它只能有一个子视图。
    重要提示:此版面必须将属性
    layout\u height
    设置为
    wrap\u content
    ,否则ScrollView将没有比自身更大的内容可滚动
  • 我还将从XML中删除根布局,并将ScrollView保留为根视图。
    仅仅是因为它毫无意义,而且需要layoutiner做额外的工作

  • 编辑:您的布局也需要更加复杂。
    这让我相信你在ScrollView中没有一个孩子(你有)


    不过,第1项应该可以解决您的问题

    Scrollview布局只能有一个子布局。在发布的XML中仍然有两个线性布局子项

    这在ScrollView的Android开发者文档的第一段中进行了解释:
    最后,我找到了答案。问题来自滚动视图中的fillviewport。如果删除fillviewport并为listview设置固定大小,您可以滚动。

    因此,它应该只有一个子项,但查看您的代码,我认为您确实拥有它。另外,由于您使用的是RelativeLayout,您能看到它是否以某种方式结束在一个循环中,重新测量您的显示,因为它是scrollview吗?相对长度适应最大值?我会尝试将所有RelativeLayout更改为LinearLayout,只是想看看情况是否如此。还有,你为什么不删除根目录下的LinearLayout并将ScrollView保留为根目录?我按照你说的做了,但结果没有什么不同。你在ScrollView中有一个ListView,这可能不起作用?检查此链接:Is明确表示您不应在scrollview中使用listview。我按您所说的做了,但未做任何更改。请使用最新的XML更新您的问题?对不起,我的原始答案中有一项,但我已将其删除,因为您的代码已经正确。那么当你改变我的建议时,你一定也意外地改变了它。查看滚动视图内部的线性布局,最上面的一个。其
    layout\u height
    设置为
    match\u parent
    。不可能,所以请将其更改为
    wrap\u content
    (仅此而已)。我将它们放在一个线性布局中。