Reputation: 3767
I have LinearLayout that has child views. The child views are stack one at the top of the other because the parent layout's orientation is vertical. All the children have their height and width wrap_content so they move freely anywhere within the parent layout. User can move the views and remove them as they wish. When the user removes a view, the parent layout height resizes. So far my code works well.
But when the user moves one view to the side of another view I would like the parent layout to resize it's height the same way as if the user removed the view. I tried to get the height of the parent and subtract the distance the child moved and redraw the layout but that didn't work. I also tried other ways but I have not been successful yet. Can someone help me?
Upvotes: 0
Views: 394
Reputation: 629
You can use GridView for your case, where you can set the number of columns (android:numColumns
) to 1, when vertically aligned and when moving to the side make it to 2.
Here is the documentation on how to use GridView https://developer.android.com/guide/topics/ui/layout/gridview.html
<GridView android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_margin="10dp"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:verticalSpacing="10dp" />
Upvotes: 1