0
votes

I put a scrollview around a Relative Layout that I am adding to dynamically. If I set the height of the Relative Layout to a fixed amount that goes off of the page the scrollview will work.

Example:

 <ScrollView 
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:fillViewport="true" >

    <RelativeLayout
        android:id="@+id/llcustomrow"
        android:layout_width="match_parent"
        android:layout_height="800dp" >
    </RelativeLayout>
</ScrollView>

But I need the RelativeLayout to be able to hold however many items I add to it dynamically o I set The relativelayout height to wrap_content. But once I add enough items to the relative layout so that they are going off the screen the Scrollview doesnt register

Below is how I am dynamically adding to the relative layout

LinearLayout mLinearLayout;
RelativeLayout rlcopy;
RelativeLayout[] rArray = new RelativeLayout[20];
int counter = 0;
RelativeLayout llcustomrow;
RelativeLayout.LayoutParams paramsleft; 


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mLinearLayout = (LinearLayout) inflater.inflate(
            R.layout.customworkout, container, false);

     paramsleft = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                                                RelativeLayout.LayoutParams.WRAP_CONTENT);


    llcustomrow = (RelativeLayout)mLinearLayout.findViewById(R.id.llcustomrow);

    for(int i = 0;i<=rArray.length-1;i++){
        rArray[i] = (RelativeLayout)View.inflate(getActivity(), R.layout.addworkoutlayout, null); 
            paramsleft.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
             paramsleft.setMargins(10, 0, 0, 0);
             rArray[i].setLayoutParams(paramsleft);

    }
    Button bAdd = (Button) mLinearLayout.findViewById(R.id.bAddExcercise);



    bAdd.setOnClickListener(new OnClickListener() {         
        @Override
        public void onClick(View v) {
                 rArray[counter].setY(rArray[counter-1].getY() + (rArray[counter-1].getHeight() +25));

             llcustomrow.addView(rArray[counter]);  
             counter++;

        }
    });


    return mLinearLayout;
}

Thanks

3
have u tried getting the size of the relative layout after you have added your widgets. Check that and see if it has grown in size bigger than the containing ScrollView and the window ofcourse - Pulkit Sethi

3 Answers

0
votes

Why are you using RelativeLayout? I'd advise switching to LinearLayout.

0
votes

TRY THIS it will work for me

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


        <RelativeLayout
            android:id="@+id/outer_ll"
            android:layout_width="match_parent"
            android:layout_height="900dp"
            android:background="#E7D687"

           >



        </RelativeLayout>
        </ScrollView>
-2
votes

change the layout_height of your RelativeLayout to match_parent.

it will solve the problem.