0

I would start with my goal. What I want to achieve is to have layout which is 3 times bigger then real screen of phone.

Right now I try to test my solution, but I have problem with scrolling. This is how look my layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="400dp"
        tools:context=".Zo"
        android:id="@+id/zo_root"
>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="9">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:background="@color/Red"
        ></FrameLayout >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:background="@color/Yellow"
        ></FrameLayout >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:background="@color/Blue"
        ></FrameLayout >
</LinearLayout>
</ScrollView>

My code behind:

    @Override
    protected void onCreate (Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zo);
        setParameterForScroolView();   
    }

    private void setParameterForScroolView()
    {
        ParameterKeeper parameterKeeper = new ParameterKeeper(this);
        LinearLayout linearLayout = (LinearLayout)findViewById(R.id.zo_root);
        linearLayout.getLayoutParams().height = parameterKeeper.getHeightOfScreen() *3;       

    }

The code behind works well, cause my whole screen is red, but I can't scroll it at all.

There was answer which said, that I need to remove from scrollView android:fillViewport="true". After that my LinearLayout diseapers like in this question.

I added LinearLayout as root (source) but it not helped me at all.

Have you got any idea to solve it?

I try also set height 1600dp instead 400dp for Root LinearLayout in xml to be sure, that it's not problem with recalculating view. It's not working too.

Community
  • 1
  • 1
MyWay
  • 1,011
  • 2
  • 14
  • 35

2 Answers2

1

You are changing the size of the wrong layout. you suppose to modify the height of the first layout inside the scroll view.

Zong
  • 6,160
  • 5
  • 32
  • 46
hasan
  • 23,815
  • 10
  • 63
  • 101
  • 1
    And height for root layout should be set as match_parent? – MyWay Sep 16 '15 at 15:13
  • it doesn't work it fit child linear layout to screen even if i set for it huge amount of dp like 2000dp. The only solution was to set height for every layout. I would put solution today, anyway thx for help – MyWay Sep 16 '15 at 17:26
0

Some way scroll doesn't work if the child elements have layout_weight and I change programmatically value of height in parent's view.

In my case the only way to make it works was to set height equal to size of screen in every of frame layout in code of activity. This way I could reach my goal which was to have layout height == 3 x real screen size

MyWay
  • 1,011
  • 2
  • 14
  • 35