2

I have created a scrollview and inside I placed a LinearLayout containing an image a text and a button. Unfortunately when the app displays this layout the scrollview's starting position is in the middle, displaying the text instead of the top, displaying the image.

I have tried programatically the scrollto and it didnt work. I have also tried the requestfocus in the XML and it didn't work.

Any ideas?

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/sv" android:layout_width="fill_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/rregeneratingcream" /> <EditText android:id="@+id/etDescription" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textMultiLine" android:enabled="false" android:background="#00000000" /> <Button android:id="@+id/buttonRegeneration" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Next" /> </LinearLayout> </ScrollView> 
5
  • Is the keyboard open when this happens? Commented Dec 6, 2013 at 6:35
  • no and the edittext is disabled Commented Dec 6, 2013 at 6:39
  • set edit-ext focus-able false.When click the edit-text to enable the focus of the edit-text.now the scroll view from start position. Commented Dec 6, 2013 at 6:41
  • Thanks! This one worked! Commented Dec 6, 2013 at 6:44
  • Try with putting ScrollView inside relative layout.. Commented Dec 6, 2013 at 6:44

2 Answers 2

1

Try this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/sv" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:layout_alignParentTop="true"/> <EditText android:id="@+id/etDescription" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:layout_below="@+id/imageView1" android:inputType="textMultiLine" android:focusable="false" android:background="#00000000" /> <Button android:id="@+id/buttonRegeneration" android:layout_width="fill_parent" android:layout_below="@+id/etDescription" android:layout_height="wrap_content" android:text="Next" /> </RelativeLayout> </ScrollView> 

And let me know if you need any further help.

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

2 Comments

still the same problem
didnt work but the key was to set the edittext to focusable false
0

You can use the Custom Vertical ScrollView like this :

package com.xyz.utils; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.widget.ScrollView; public class VerticalScrollview extends ScrollView { public VerticalScrollview(Context context) { super(context); } public VerticalScrollview(Context context, AttributeSet attrs) { super(context, attrs); } public VerticalScrollview(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: Log.i("VerticalScrollview", "onInterceptTouchEvent: DOWN super false"); super.onTouchEvent(ev); break; case MotionEvent.ACTION_MOVE: return false; // redirect MotionEvents to ourself case MotionEvent.ACTION_CANCEL: Log.i("VerticalScrollview", "onInterceptTouchEvent: CANCEL super false"); super.onTouchEvent(ev); break; case MotionEvent.ACTION_UP: Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false"); return false; default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action); break; } return false; } @Override public boolean onTouchEvent(MotionEvent ev) { super.onTouchEvent(ev); Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction()); return true; } } 

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.