How Do I Make my Screen Scrollable in Android Eclipse

前端 未结 1 1469
心在旅途
心在旅途 2021-01-17 07:06

This is the XML code I have before I attempt to adjust it to be scrollable:




        
相关标签:
1条回答
  • 2021-01-17 07:46

    Make sure you leave the version/encoding line at the very top of your file.

    Change RelativeLayout to ScrollView and then nest a RelativeLayout section (containing all of your widgets) inside that new ScrollView.

    Make sure you give the RelativeLayout some dimensions, which should be the same as the ScrollView width and height dimensions.

    The reason for this nesting of the RelativeLayout that contains all the widgets is that a ScrollView element can only have one child element (in this case, the RelativeLayout, which then has its own children).

    Therefore this code:

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

    Turns into this code:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >      
    
            <!-- all your widgets -->
    
        </RelativeLayout>
    
    </ScrollView>
    
    0 讨论(0)
提交回复
热议问题