I want to create a dynamically extending layout that may grow reflecting to user\'s input. First, I\'ve created an activity layout that allows scrolling in both directions
The solution is surprisingly simple.
In the activity layout, a RelativeLayout node (the one with content ID) should use the custom layout class that overrides the onMeasure method.
So here is the fix for the activity layout:
<com.sample.MyRelativeLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="false"
android:clipToPadding="false" >
</com.sample.MyRelativeLayout>
and here is the class implementation:
public class MyRelativeLayout extends RelativeLayout {
public MyRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(0, 0);
}
}
Note that I don't have to calculate anything, passing (0, 0) works just fine.
Frankly speaking, I don't yet understand all pros and cons of this solution, but it works properly. The only issue that I have noticed so far is that the more items I expand, the slower the UI responds.
I'll appreciate any comments or suggestions.