Question: I am new to XML and I have been messing with XML for a while but couldn't achieve the look that I wanted. I wanted to create a square layout depending on the phones width. For example the phone's width is 768X1280, how do I setup a layout that is 768x768 (perfect square) on the top of my screen leaving out the rest of the space for buttons and other stuffs?

Answer: 
You can make it dynamically (in onCreate Method)

```
Display display = getWindowManager().getDefaultDisplay();

        ActualLayoutWidth = display.getWidth();

params = new LinearLayout.LayoutParams(ActualLayoutWidth ,
                ActualLayoutWidth );

        yourLayout.setLayoutParams(params);

```
You can use Constraint layout for perfect square 

```
<android.support.constraint.ConstraintLayout
    android:id="@+id/ll_second"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/main_second"
    android:layout_marginStart="20dp"
    android:layout_marginEnd="20dp"
    android:layout_marginBottom="10dp"
    android:orientation="horizontal">

    <FrameLayout
        android:id="@+id/f1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginEnd="5dp"
        android:background="@android:color/black"
        app:layout_constraintDimensionRatio="H,1:1"
        app:layout_constraintEnd_toStartOf="@+id/f2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </FrameLayout>

    <FrameLayout
        android:id="@+id/f2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="5dp"
        android:background="@android:color/black"
        app:layout_constraintDimensionRatio="H,1:1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@+id/f1">
    </FrameLayout>
</android.support.constraint.ConstraintLayout>

```