Is it good idea to use Constrain layout inside Scrollview in Android?

Viewed 179

I am working as OEM developer where we are using common GUI library for all Applications. In our application we are extending that GUI library which carry ScrollView as base layout for my application. Now my team is planning to use constrain layout in Application. Can we use constrain layout inside Scroll View?

I converted linear layout into constrain layout using Android Design tool. But scrolling is not working.

<ScrollView
    style="@style/Body_ScrollView"
    android:id="@+id/no_sim_layout">

    <LinearLayout style="@style/Body.LinearLayout.No_Sim">
        <-- All other child views are going here-->
    </LinearLayout>

</ScrollView>

Want to convert into

<ScrollView
    style="@style/Body_ScrollView"
    android:id="@+id/no_sim_layout">

    <ConstrainLayout style="@style/Body.LinearLayout.No_Sim">
           <-- All other child views are going here-->
    </ConstrainLayout>

</ScrollView>
1 Answers

Yes, definitely the Constraint-layout first understand this:

Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.Which recommends of Relative-layout rules.

More-ever it provide dynamic view alignment property as constraints, baseline, chaining of views and many other which provide seamless flatten hierarchy. If we used Constraint in Scrollview, we dont need to manage each view property like weighing in LinearLayout and many others. It much more simple and directly obtained benefits from provided dependencies.

<ConstrintLayout>
   <ScrollView>
    <ConstrintLayout>
        //Single ParentConstrain else child
    </ConstrintLayout>
   </ScrollView>
</ConstrintLayout>

If goes by other way, this make your complex XML code more hard to understand and is heavy to build UI based on weighing and position calculated at run time on machine.

Constraint are directly benefit from input dependencies.

 <ConstrintLayout>
       <ScrollView>
        <LinearLayout>
            //Many different view to manage view
        </LinearLayout>
       </ScrollView>
    </ConstrintLayout>
Related