View horizontal scroll in android

I'm starting Android development, and I'm trying to create a horizontal scroll view that will contain different layouts.

error I encountered: horozontal scroll view can contain only one direct child. inform in advance

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tool" android:id="@+id/horizontalScrollView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:fillViewport="true" > <LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="horizontal" android:background="#ff0000"> <LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="horizontal" android:background="#ff0000"> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="horizontal" android:background="#00ff00"> </LinearLayout> </LinearLayout> </HorizontalScrollView> 
+4
source share
1 answer

Not only Horizontal, but also any vertical scrollview will also give this error. An error means that there should be only one child in a scrollview, and this child can contain any number of children.

So, the bottom line is that you have to make only one direct child element for scrolling and make your layout in this child only as

  <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tool" android:id="@+id/horizontalScrollView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:fillViewport="true" > <LinearLayout android:id="@+id/directchild" android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="horizontal" android:background="#ff0000"> </LinearLayout> </HorizontalScrollView> 

Now create the desired layout in the directchild layout. You will not get any error and then

+4
source

Source: https://habr.com/ru/post/1439872/


All Articles