Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.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
Java ScrollView没有';我不能在不同的设备上工作_Java_Android_Xml_Android Layout_Scrollview - Fatal编程技术网

Java ScrollView没有';我不能在不同的设备上工作

Java ScrollView没有';我不能在不同的设备上工作,java,android,xml,android-layout,scrollview,Java,Android,Xml,Android Layout,Scrollview,我使用RelativeLayout和LinearLayout创建了一个简单的ScrollView,ScrollView在较新的设备上运行良好,我在Nexus 5上进行了测试,一切正常,但当我在较旧的设备(不太旧)上进行测试时,滚动不起作用,布局仅显示视图的顶部,不允许我进行滚动 因此,我的xml如下所示: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.andro

我使用RelativeLayout和LinearLayout创建了一个简单的ScrollView,ScrollView在较新的设备上运行良好,我在Nexus 5上进行了测试,一切正常,但当我在较旧的设备(不太旧)上进行测试时,滚动不起作用,布局仅显示视图的顶部,不允许我进行滚动

因此,我的xml如下所示:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">


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

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            app:srcCompat="@android:drawable/ic_menu_camera"
            android:elevation="2dp"
            app:layout_widthPercent="90%"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="90%"
            app:layout_marginLeftPercent="80%"
            app:backgroundTint="#f1c40f"
            android:onClick="capture"/>

        <include
            layout="@layout/custom_toolbar"
            android:id="@+id/my_toolbar"
            app:layout_widthPercent="100%"
            app:layout_heightPercent="8%"
            app:layout_marginTopPercent="0%"
            app:layout_marginLeftPercent="0%" />



        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/SpecieName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="85%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/GenreName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="genrePressed"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="95%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/FamilyName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="familyPressed"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="105%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/textView8"
            android:text="Espécie"
            android:textSize="14dp"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="85%"
            app:layout_marginLeftPercent="5%"
 />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/textView7"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="95%"
            app:layout_marginLeftPercent="5%"
            android:text="Género"
            android:textSize="14dp" />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/Family"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="105%"
            app:layout_marginLeftPercent="5%"
            android:text="Familia"
            android:textSize="14dp" />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/specieDescription"
            android:textSize="14dp"
            app:layout_widthPercent="90%"
            android:layout_height="wrap_content"
            app:layout_marginTopPercent="120%"
            app:layout_marginLeftPercent="5%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/descricaoTit"
            android:text="Descrição"
            android:textSize="14dp"
            app:layout_widthPercent="30%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="115%"
            app:layout_marginLeftPercent="5%"/>

        <ImageView
            android:id="@+id/plantImage"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            app:layout_widthPercent="80%"
            app:layout_heightPercent="50%"
            app:layout_marginTopPercent="10%"
            app:layout_marginLeftPercent="10%"
            app:srcCompat="@drawable/color_cursor_white" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/gallery"
            app:layout_widthPercent="100%"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="62%"
            app:layout_marginLeftPercent="0%" />

        <RelativeLayout
            app:layout_widthPercent="40%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="75%"
            app:layout_marginLeftPercent="5%"
            android:onClick="showMap">

            <TextView
                android:id="@+id/googleMapsText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/imageView6"
                android:layout_alignBottom="@+id/imageView6"
                android:text="Ver no mapa" />

            <ImageView
                android:id="@+id/imageView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_facebook_placeholder_for_locate_places_on_maps"
                android:tint="#F90101" />
        </RelativeLayout>

    </android.support.percent.PercentRelativeLayout>
        </LinearLayout>
</ScrollView>

我试图用线性布局包围我的布局,试图遵循stackoverflow用户建议的方法,但没有成功


有什么想法吗?

试试看。我不确定它会不会工作,因为我不知道你的百分比布局

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">


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

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            app:srcCompat="@android:drawable/ic_menu_camera"
            android:elevation="2dp"
            app:layout_widthPercent="90%"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="90%"
            app:layout_marginLeftPercent="80%"
            app:backgroundTint="#f1c40f"
            android:onClick="capture"/>

        <include
            layout="@layout/custom_toolbar"
            android:id="@+id/my_toolbar"
            app:layout_widthPercent="100%"
            app:layout_heightPercent="8%"
            app:layout_marginTopPercent="0%"
            app:layout_marginLeftPercent="0%" />



        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/SpecieName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="85%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/GenreName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="genrePressed"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="95%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/FamilyName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="familyPressed"
            android:textColor="@color/nephritis"
            android:textSize="14dp"
            app:layout_widthPercent="60%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="105%"
            app:layout_marginLeftPercent="30%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/textView8"
            android:text="Espécie"
            android:textSize="14dp"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="85%"
            app:layout_marginLeftPercent="5%"
 />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/textView7"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="95%"
            app:layout_marginLeftPercent="5%"
            android:text="Género"
            android:textSize="14dp" />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/Family"
            app:layout_widthPercent="25%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="105%"
            app:layout_marginLeftPercent="5%"
            android:text="Familia"
            android:textSize="14dp" />

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/specieDescription"
            android:textSize="14dp"
            app:layout_widthPercent="90%"
            android:layout_height="wrap_content"
            app:layout_marginTopPercent="120%"
            app:layout_marginLeftPercent="5%"/>

        <com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
            android:id="@+id/descricaoTit"
            android:text="Descrição"
            android:textSize="14dp"
            app:layout_widthPercent="30%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="115%"
            app:layout_marginLeftPercent="5%"/>

        <ImageView
            android:id="@+id/plantImage"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            app:layout_widthPercent="80%"
            app:layout_heightPercent="50%"
            app:layout_marginTopPercent="10%"
            app:layout_marginLeftPercent="10%"
            app:srcCompat="@drawable/color_cursor_white" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/gallery"
            app:layout_widthPercent="100%"
            app:layout_heightPercent="10%"
            app:layout_marginTopPercent="62%"
            app:layout_marginLeftPercent="0%" />

        <RelativeLayout
            app:layout_widthPercent="40%"
            app:layout_heightPercent="5%"
            app:layout_marginTopPercent="75%"
            app:layout_marginLeftPercent="5%"
            android:onClick="showMap">

            <TextView
                android:id="@+id/googleMapsText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/imageView6"
                android:layout_alignBottom="@+id/imageView6"
                android:text="Ver no mapa" />

            <ImageView
                android:id="@+id/imageView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_facebook_placeholder_for_locate_places_on_maps"
                android:tint="#F90101" />
        </RelativeLayout>

    </android.support.percent.PercentRelativeLayout>
        </LinearLayout>
</android.support.v4.widget.NestedScrollView>

滚动视图的子视图应设置为包装内容。如果将其设置为匹配父项,它将填充ScrollView的区域,并且永远不会滚动,因为它不会比ScrollView大

尝试将子LinearLayout布局高度更改为包裹内容或特定大小(以dp为单位),而不是匹配父项

编辑:


另外,尝试将滚动视图的高度从匹配父对象更改为换行内容。因为只有当滚动视图的总高度大于父视图的高度时,滚动视图才会启用滚动

你试过嵌套的scrollview吗?我只需要1个scrollview仍然没有:/,我只是不明白为什么它在普通设备上工作