簡體   English   中英

ScrollView在其他設備上不起作用

[英]ScrollView doesn't work on a different device

我在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的子視圖應設置為wrap_content。 如果將其設置為match_parent,它將填充ScrollView的區域並且永遠不會滾動,因為它不會大於ScrollView。

嘗試將子級LinearLayout layout_height更改為wrap_content或特定大小(以dp為單位),而不是match_parent。

編輯:

另外,嘗試將滾動視圖的高度從match_parent更改為wrap_content。 因為滾動視圖僅在其總高度大於父視圖的高度時才啟用滾動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM