17

I've been using scroll view in my apps, but the thing is that this is the first time I've to draw something longer than the default size screen.

The XML Design screen shows a fixed 3.7inch (or larger) screen. What if I want to add more objects? How do I scroll down while designing in Eclipse?

Adinia
  • 3,722
  • 5
  • 40
  • 58
Asim
  • 6,962
  • 8
  • 38
  • 61

9 Answers9

11

You can change screen size to custom.. try this.. click on current screen button, and select "Add Custom", then scroll down and select Custom and click "New" in right top corner.. Then write your custom size for screen and click "OK", then again "OK".. Afterward again click on your current screen button and select your custom size.. Done! Hope helped!

Be sure that this buttons is selected.. enter image description here

Henrik
  • 339
  • 3
  • 13
  • 1
    There are so many parameters there. Can you kindly specify what parameters I need for making the screen longer? – Asim Oct 22 '12 at 08:59
4

Try temporarily setting android:scrollY on the ScrollView. I haven't tried this but it should, in theory, work. Just remember to remove the attribute when publishing the app.

Felix
  • 88,392
  • 43
  • 149
  • 167
2

As of Android API 19 this solution has changed. Here's what worked for me.

Go to your Android Virtual Device Manager (in Eclipse this is in Window > Android Virtual Device Manager), once there go to the Device Definitions tab and create a New Device. Name it something memorable like "Long Scroller".

The Create New Device screen

In the Edit/Create Device screen set the vertical dimensions to however long you think your scroll view will be (7000px was more than enough for my uses). You can also tweak it later.

Restart Eclipse, open your long scrollview layout, and your long scroller will appear among your preview layouts.

Andrew T.
  • 2,088
  • 1
  • 20
  • 42
2

Add android:scrollY="300dp" to your layout. Tt will scroll the content 300dp up.

before adding the android:scrollY="300dp" to layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.javamad.user_profile"
>

you can see no space for design

After adding the android:scrollY="300dp" to layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.javamad.user_profile"
    android:scrollY="300dp"
>

you see the space for design.

Opal
  • 81,889
  • 28
  • 189
  • 210
Nirmal Dhara
  • 2,121
  • 18
  • 27
2

Add something like android:layout_marginTop="-300dp" attribute to immediate ScrollView child.

vbarinov
  • 503
  • 4
  • 10
1

Try setting your inner layout to a fixed height. So your code should be like

<ScrollView
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
<RelativeLayout
     android:layout_height="900dp"
>
</ReleativeLayout>
</ScrollView>

This should work

Androyds
  • 391
  • 1
  • 3
  • 20
0
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       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"
       tools:context=".AdminControlPanel" 
       android:scrollY="200dp">

this android:scrollY makes your designing screen longer in Y direction...add your components towards down

  • In case it is not obvious, the scrollY attribute should be added to the child of the ScrollView, not the ScrollView itself. – Paul LeBeau Jan 09 '15 at 07:40
0

I usually just use negative margin. It works on scroll view as on a item inside.

oneat
  • 10,778
  • 16
  • 52
  • 70
0

This was my solution: I subclassed ScrollView to take a scrollY param that is only used when isInEditMode().

public class MyScollView extends ScrollView {

    private int scrollY = 0;

    private void init(Context context, AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyScrollView);
        scrollY = a.getInt(R.styleable.MyScrollView_scrollY, 0);
        a.recycle();
    }

    public MyScollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context, attrs);
    }

    public MyScollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public MyScollView(Context context) {
        super(context);
    }

    @Override
    public void computeScroll() {
        if (isInEditMode()) {
            scrollTo(0, scrollY);
        }
    }

}

This goes into your attrs.xml file

<declare-styleable name="MyScrollView">
    <attr name="scrollY" format="integer"/>
</declare-styleable>
Fracdroid
  • 1,135
  • 10
  • 15
  • One caveat I found is that the rendered screen is out of sync with the pickable UI elements. You can still choose UI elements form the outline dialog which is how I usually do it anyway. Just something to be aware of. – Fracdroid Oct 15 '15 at 17:40