is it possible to have a LinearLayout inside a LinearLayout with equal height and width dynamically? i don't want to specify the values, just that the height is the same size of the possible width.
thx
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.
XML attributes Drawable to use as a vertical divider between buttons. android:gravity. Specifies how an object should position its content, on both the X and Y axes, within its own bounds.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code we have taken one text view with background as border so we need to create a file in drawable as boarder.
I have the same problem and i couldn't find a way to solve this using only xml. So i wrote custom layout and reference it from xml.
public class SquareLayout extends LinearLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
// or you can use this if you want the square to use height as it basis
// super.onMeasure(heightMeasureSpec, heightMeasureSpec);
}
}
and reference it in xml like this
<your.package.SqureLayout .....
</your.package.SquareLayout>
If there is easiest solution i'll be glad to know it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With