如何使用滚动滑块使屏幕上下滚动?

时间:2017-04-28 08:29:05

标签: android gridview scrollbar

我是Android开发的新手。任何人都可以帮我解决这个问题吗? 每当我试图向下移动滚动条时,整个屏幕都会向上移动。 我创建的XML如下所示。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:id="@+id/backButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Back"
    android:textAppearance="@style/TextAppearance.AppCompat.Button" />


<GridView
    android:id="@+id/gridView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnWidth="190dp"
    android:fadeScrollbars="false"
    android:fitsSystemWindows="true"
    android:gravity="center"
    android:horizontalSpacing="0dp"
    android:numColumns="2"
    android:scrollbarSize="20dp"
    android:scrollbarStyle="outsideInset"
    android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
    android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
    android:scrollbars="vertical"
    android:stretchMode="columnWidth"
    android:verticalSpacing="0dp"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:fastScrollAlwaysVisible="false"
    android:fastScrollEnabled="false"/>



</LinearLayout>

1 个答案:

答案 0 :(得分:0)

您已使用LinearLayout作为容器来显示视图。如果你没有在其中定义方向,那么默认情况下需要&#34;水平&#34;取向。在您的情况下,您将方向定为垂直方向 改变你的线性布局

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

以下:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

将android:orientation定位为&#34; vertical&#34;