ScrollView不会滚动

时间:2013-11-05 21:11:57

标签: 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>

2 个答案:

答案 0 :(得分:2)

替换:

    <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>

答案 1 :(得分:0)

首先,您没有RelativeLayout的关闭标记。

如果你想要scrollview工作,那么你必须在scrollview中插入足够的视图来填充屏幕高度