android - ScrollView 不会滚动

标签 android android-layout

我是 Android 编程的新手(实际上是昨天开始的),我无法让 ScrollView 滚动。我有一堆按钮无法全部显示在屏幕上,所以我尝试添加滚动功能。但是,这不起作用。如果有帮助,我正在运行模拟器。这是我的 XML:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".UnleashedMainPageActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/unleashed_Main" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:text="@string/choose_Mod" />

    <Button
        android:id="@+id/button4"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_alignRight="@+id/textView2"
        android:layout_below="@+id/textView2"
        android:text="Applied Energistics" />

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button4"
        android:layout_alignRight="@+id/button4"
        android:layout_below="@+id/button4"
        android:text="Buildcraft" />

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignRight="@+id/button1"
        android:layout_below="@+id/button1"
        android:text="Computer Craft" />

    <Button
        android:id="@+id/button3"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button2"
        android:layout_alignRight="@+id/button2"
        android:layout_below="@+id/button2"
        android:text="Ender Storage" />

    <Button
        android:id="@+id/button5"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button3"
        android:layout_alignRight="@+id/button3"
        android:layout_below="@+id/button3"
        android:text="Equivalent Exchange 3" />

    <Button
        android:id="@+id/button6"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button5"
        android:layout_alignRight="@+id/button5"
        android:layout_below="@+id/button5"
        android:text="ExtraBiomes/Biomes O' Plenty" />
    <Button
        android:id="@+id/button7"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button6"
        android:layout_alignRight="@+id/button6"
        android:layout_below="@+id/button6"
        android:text="Factorization" />
    <Button
        android:id="@+id/button8"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button7"
        android:layout_alignRight="@+id/button7"
        android:layout_below="@+id/button7"
        android:text="Forestry" />
    <Button
        android:id="@+id/button9"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button8"
        android:layout_alignRight="@+id/button8"
        android:layout_below="@+id/button8"
        android:text="IndustrialCraft 2" />

    <Button
        android:id="@+id/button10"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button9"
        android:layout_alignRight="@+id/button9"
        android:layout_below="@+id/button9"
        android:text="MineFactory Reloaded" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button10"
        android:layout_alignLeft="@+id/button4"
        android:layout_alignTop="@+id/button4"
        android:orientation="vertical" >

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
            </LinearLayout>
        </ScrollView>

    </LinearLayout>

</RelativeLayout>

最佳答案

替换:

    <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
                    android:paddingLeft="@dimen/activity_horizontal_margin"
                    android:paddingRight="@dimen/activity_horizontal_margin"
                    android:paddingTop="@dimen/activity_vertical_margin"
                    tools:context=".UnleashedMainPageActivity" >
               <ScrollView
                         android:id="@+id/scrollView1"
                         android:layout_width="match_parent"
                         android:layout_height="match_parent" >

                                <LinearLayout
                                         android:layout_width="match_parent"
                                         android:layout_height="match_parent"
                                         android:orientation="vertical" >
                                      <TextView
                                         android:id="@+id/textView1"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:text="@string/unleashed_Main" />

                                      <TextView
                                         android:id="@+id/textView2"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/textView1"
                                         android:layout_below="@+id/textView1"
                                         android:text="@string/choose_Mod" />

                                     <Button
                                         android:id="@+id/button4"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/textView2"
                                         android:layout_alignRight="@+id/textView2"
                                         android:layout_below="@+id/textView2"
                                         android:text="Applied Energistics" />
                                    <Button
                                         android:id="@+id/button1"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button4"
                                         android:layout_alignRight="@+id/button4"
                                         android:layout_below="@+id/button4"
                                         android:text="Buildcraft" />

                                    <Button
                                         android:id="@+id/button2"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button1"
                                         android:layout_alignRight="@+id/button1"
                                         android:layout_below="@+id/button1"
                                         android:text="Computer Craft" />

                                    <Button
                                         android:id="@+id/button3"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button2"
                                         android:layout_alignRight="@+id/button2"
                                         android:layout_below="@+id/button2"
                                         android:text="Ender Storage" />

                                    <Button
                                         android:id="@+id/button5"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button3"
                                         android:layout_alignRight="@+id/button3"
                                         android:layout_below="@+id/button3"
                                         android:text="Equivalent Exchange 3" />

                                    <Button
                                         android:id="@+id/button6"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button5"
                                         android:layout_alignRight="@+id/button5"
                                         android:layout_below="@+id/button5"
                                         android:text="ExtraBiomes/Biomes O' Plenty" />
                                    <Button
                                         android:id="@+id/button7"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button6"
                                         android:layout_alignRight="@+id/button6"
                                         android:layout_below="@+id/button6"
                                         android:text="Factorization" />
                                    <Button
                                         android:id="@+id/button8"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button7"
                                         android:layout_alignRight="@+id/button7"
                                         android:layout_below="@+id/button7"
                                         android:text="Forestry" />
                                      <Button
                                         android:id="@+id/button9"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button8"
                                         android:layout_alignRight="@+id/button8"
                                         android:layout_below="@+id/button8"
                                         android:text="IndustrialCraft 2" />

                                     <Button
                                         android:id="@+id/button10"
                                         style="?android:attr/buttonStyleSmall"
                                         android:layout_width="wrap_content"
                                         android:layout_height="wrap_content"
                                         android:layout_alignLeft="@+id/button9"
                                         android:layout_alignRight="@+id/button9"
                                         android:layout_below="@+id/button9"
                                         android:text="MineFactory Reloaded" />
                                 </LinearLayout>
                      </ScrollView>
                </RelativeLayout>

关于android - ScrollView 不会滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19799064/

相关文章:

java - Android 禁用按钮网格

android - Textview 布局以编程方式在 ScrollView 中垂直和水平居中

android - 尝试在 Activity 中 inflated layout 不起作用

android - animateLayoutChanges 不适用于嵌套布局?

java - 动态获取 ListView 项

android - 在 FrameLayout 中缩放 ImageView ontouch

javascript - jquery 的 document.ready 函数在 android 中不起作用

java - AndEngine Box2d - 如何避免联合 "stretching"?

android - android 4.1.1 自定义通知中的选取框问题

android - 在 View 滚动时隐藏工具栏