0

I am a beginner in Android studio programming and I am making a small app for my arduino. The screen size is too small for a Relative layout, so now I am trying to change it to a ScrollView and I don't know how to. So can anyone help me? Thank you!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 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" > <TextView android:id="@+id/testView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/txtString" android:text="" android:textSize="15sp" /> <TextView android:id="@+id/txtString" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_alignLeft="@+id/testView1" android:layout_alignParentBottom="true" android:text="" android:textSize="15sp" /> <Button android:id="@+id/buttonOn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Shrani nastavitve" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <Button android:id="@+id/buttonOff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/buttonOn" android:layout_alignParentRight="true" android:text="Beri nastavitve" /> <TextView android:id="@+id/sensorView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Kot zamika = " android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="20dp" android:layout_below="@+id/seekBar1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:id="@+id/sensorView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Min obrati = " android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="20dp" android:layout_below="@+id/seekBar3" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:id="@+id/sensorView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Trenutni obrati : " android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="20dp" android:layout_alignBaseline="@+id/testView1" android:layout_alignBottom="@+id/testView1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:id="@+id/sensorView0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Čas zamika = " android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="20dp" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <SeekBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/seekBar1" android:max="100" android:indeterminate="false" android:layout_below="@+id/textView1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_toStartOf="@+id/buttonOff" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> <SeekBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/seekBar2" android:max="180" android:indeterminate="false" android:layout_below="@+id/textView3" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignRight="@+id/seekBar4" android:layout_alignEnd="@+id/seekBar4" /> <SeekBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/seekBar3" android:max="5000" android:indeterminate="false" android:layout_below="@+id/textView2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignRight="@+id/seekBar2" android:layout_alignEnd="@+id/seekBar2" /> <TextView android:id="@+id/sensorView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Čas mirovanja = " android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="20dp" android:layout_below="@+id/seekBar2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <SeekBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/seekBar4" android:max="3000" android:indeterminate="false" android:layout_below="@+id/textView4" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignRight="@+id/buttonOff" android:layout_alignEnd="@+id/buttonOff" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView1" android:textSize="20dp" android:layout_below="@+id/sensorView0" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView2" android:textSize="20dp" android:layout_below="@+id/sensorView1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView3" android:textSize="20dp" android:layout_below="@+id/sensorView2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView4" android:textSize="20dp" android:layout_below="@+id/sensorView4" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> 

0

3 Answers 3

0

You can always use the GUI editor to help you. Under container, choose ScollView and drag it to your screen. Then add your elements. It will work.

As an alternative, you can surround your current code by

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentTop="true"> 

and

</ScrollView> </RelativeLayout> 

Make sure to remove the line

xmlns:android="http://schemas.android.com/apk/res/android" 

from your existing layout, that line needs to be on the highest parent.

What this does is making a layout with only the scrollview in it. Then it places all components in the view, so you will have a scrollable view with everything inside it.

Sign up to request clarification or add additional context in comments.

1 Comment

Why another RelativeLayout? ScrollView should be the parent.
0

Put above RelativeLayout inside the SrollView as below:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <!-- Your whole code goes here --> </ScrollView> 

5 Comments

I tried it you way... there are no errors but the rendering is fishi :) the app works but it does not scroll
Do you have more elements below screen now? Any textview is hidden?
elements are pushed one on another. My Xperia Z5 died and now im testing on an old Xcover. Mybe its something with the Android on the phone. I tested on my girlfirends Lenovo ( has a bigger screen) and everything fits perfectly. I don't have a 3.65" svreen preview. There is one but everything is different.
It works! I didn't see it because my seekbars are extended from left to right. If i touch the right side of the screen:) Tank you so much! I will be able to work the rest out by myself!!! +1
welcome buddy...
0

Just replace <RelativeLayout to <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
but your component cannot be loaded because ScrollView only have one direct child

Below Lines can be put into relative layout which will be on child to scroll view..

android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/someComponent" 

and some similiar positioning codes

*addition you should use scale pixel (sp) instead density pixel(dp) in a TextView.textSize

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.