1

I have the following layout:

<HorizontalScrollView
    android:id="@+id/scrollableContents"
    android:layout_above="@id/getting_started_buttons_container"
    android:layout_below="@id/getting_started_title_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <FrameLayout
        android:id="@+id/getting_started_keywords_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white">
    </FrameLayout>
</HorizontalScrollView>

In which i dynamically add views using a for loop in a container, i,m using translation to move them to right

 index = 0;
 for (Word word : wordList) {  //wordList size is 15 or more
        index++;
        view = new MyView(this, null);
        view.setTranslationX(index * 150);
        container.addView(view);
        container.invalidate();
        scrollView.requestLayout();
        scrollView.invalidate();
    }

My scrollView does not extend over the screen since it has the initial empty view. I need to see all views. Can anybody help me? I need a way to update scrollView to a width that contains all my elements

EDIT: I want to achieve something like these with a dynamically number of circles, which must extend in scrollView if there is no room on the screen. LinearLayout is not a solution....

enter image description here

2 Answers 2

1

replace RelativeLayout with horizontal LinearLayout

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

4 Comments

I need RelativeLayout or FrameLayout since I will make further translations on my views, and LinearLayout ruins my computations.
Can you explain me why RelativeLayout does not work?
I can't understand why LinearLayout doesn't work for you, but if you want to use RelativeLayout I think you need to change the width of it everytime you add a new View or add them in right/left of previous added View
I have edited my question, LinearLayout will broke my views since they will be moved next to each other
1

you used RelativeLayout as parent view. Then you will need to use LayoutParam to add Rules for setting position like toRightOf() and alignParentTop.

If you don't add rules for your views, your views will be overlapped in same place (Top and Left)

So just use LinearLayout with orientation to be easy.

Thanks. Hope this will help you.

1 Comment

I have edited my question, LinearLayout will broke my views since they will be moved next to each other

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.