安卓滚动视图不起作用,尝试了所有答案



我是Android开发的新手,我有很多内容,但滚动根本不适用于我的应用程序,尝试了堆栈溢出中的所有答案,但对我来说没有任何用处。任何帮助将不胜感激!

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbars="none" >
    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/scoreview"
            android:background="@android:color/black"
            xmlns:tools="http://schemas.android.com/tools"
            tools:context="com.example.saikumar.cricket.ScoreDisplay"
            >
            <RelativeLayout
                android:id="@+id/loadingPanel"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center" >
                <ProgressBar
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:indeterminate="true" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/matchtitle_layout">
                <Button
                    android:id="@+id/match_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="10dp"
                    android:text="Loading..."
                    android:fontFamily="monospace"
                    android:textColor="@android:color/white"
                    android:textSize="13dp"
                    android:clickable="false"
                    android:background="@color/colorPrimary"
                    />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/score_layout"
                android:visibility="gone"
                android:layout_below="@+id/matchtitle_layout"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    >
                    <TextView
                        android:id="@+id/score"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Score"
                        android:padding="10dp"
                        android:textColor="@android:color/white"
                        android:textSize="15dp"
                        android:fontFamily="monospace"
                        android:textStyle="bold"
                        />
                    <TextView
                        android:id="@+id/scoreruns"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="3"
                        android:text="Score"
                        android:fontFamily="monospace"
                        android:padding="10dp"
                        android:paddingLeft="0dp"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        android:layout_below="@+id/match_title"
                        android:layout_alignEnd="@+id/overscount" />
                </LinearLayout>
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/score_layout"
                android:id="@+id/bowler_layout"
                android:visibility="gone"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <TextView
                        android:id="@+id/bowler"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Bowler"
                        android:padding="10dp"
                        android:textColor="@android:color/white"
                        android:textSize="15dp"
                        android:fontFamily="monospace"
                        android:textStyle="bold"
                        />
                    <TextView
                        android:id="@+id/bowlername"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="3"
                        android:text="Name"
                        android:fontFamily="monospace"
                        android:padding="10dp"
                        android:paddingLeft="0dp"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        android:layout_below="@+id/match_title"
                        android:layout_alignEnd="@+id/overscount" />
                </LinearLayout>
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/innings"
                android:layout_below="@+id/bowler_layout"
                >
                <TextView
                    android:id="@+id/total"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Loading..."
                    android:padding="20dp"
                    android:fontFamily="monospace"
                    android:textSize="15dp"
                    android:textColor="@android:color/white"
                    />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/innings"
                android:id="@+id/heading_innings"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/holo_red_light"
                    android:padding="10dip"
                    >
                    <TextView
                        android:id="@+id/batsman"
                        android:layout_width="140dp"
                        android:layout_height="wrap_content"
                        android:text="BatsMan"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="R"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="B"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="4s"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="6s"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="SR"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                </LinearLayout>
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/batting_reltive_layout_one"
                android:layout_below="@+id/heading_innings"
                >
                <ListView
                    android:id="@+id/batting_runs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    tools:layout_editor_absoluteX="8dp"
                    tools:layout_editor_absoluteY="8dp"
                    android:padding="1dp"/>
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/inningstwo"
                android:layout_below="@+id/batting_reltive_layout_one"
                >
                <TextView
                    android:id="@+id/totalsecond"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Loading..."
                    android:padding="20dp"
                    android:fontFamily="monospace"
                    android:textSize="15dp"
                    android:textColor="@android:color/white"
                    />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/inningstwo"
                android:id="@+id/heading_innings_two"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/holo_red_light"
                    android:padding="10dip"
                    >
                    <TextView
                        android:layout_width="140dp"
                        android:layout_height="wrap_content"
                        android:text="BatsMan"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="R"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="B"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="4s"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="6s"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="SR"
                        android:fontFamily="monospace"
                        android:textSize="15dp"
                        android:textColor="@android:color/white"
                        />
                </LinearLayout>
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/batting_reltive_layout_two"
                android:layout_below="@+id/heading_innings_two"
                >
                <ListView
                    android:isScrollContainer="false"
                    android:id="@+id/batting_runs_two"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    tools:layout_editor_absoluteX="8dp"
                    tools:layout_editor_absoluteY="8dp"
                    android:padding="1dp"/>
            </RelativeLayout>
        </RelativeLayout>
</ScrollView>

NestedScrollView 而不是 Scrollview 应该可以解决您的问题。在一个完全不同的主题上,由于您现在开始进行Android开发,因此我建议您学习/使用RecycleView而不是ListView。RecycleView更容易实现,具有很强的逆向兼容性,并且不需要"视图持有人模式"来提高性能。这是一个链接,可以帮助您掌握一些基本概念:

https://guides.codepath.com/android/using-the-recyclerview

尝试使用NestedScrollView,问题可能是您在滚动视图中有一个列表视图。

最新更新