Skip to content Skip to sidebar Skip to footer

Add A Scrollview In Linear And Relative Layout In One Xml File

I am trying to make the contents of Relative Layout as Scrollview as its not fitting in the screen. My XML file that consists of both, Linear and Relative Layout where Linear is a

Solution 1:

If you don't want the topmost TextView to be part of the scrolling area, then you'll have to nest the RelativeLayouts into another layout, because a ScrollView can have only one direct child.

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="vertical" ><TextView... /><ScrollView... ><!-- only one direct child for scrollview: --><LinearLayout... ><RelativeLayout... /><TextView... /><RelativeLayout... /><TextView... /><RelativeLayout... /><TextView... /><RelativeLayout... /><TextView... /><!-- etc --></LinearLayout></ScrollView></LinearLayout>

Solution 2:

just put the scorolleview as parent of the RelativeLayout as follows:

<ScrollViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"><RelativeLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:scrollHorizontally="true"><ImageViewandroid:id="@+id/treadmillimage"android:layout_width="115dp"android:layout_height="93dp"android:paddingTop="10dp"android:src="@drawable/treadmill" />

.....
.....
</RelativeLayout></ScrollView>

Post a Comment for "Add A Scrollview In Linear And Relative Layout In One Xml File"