views:

525

answers:

2
+1  A: 

ok, here's a revised example:

<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent">
    <RelativeLayout android:id="@+id/magaLoginLayout"
        android:layout_height="fill_parent" android:layout_width="fill_parent">
        <Button android:text="@+id/Button01" android:id="@+id/Button01"
            android:layout_width="160dip" android:layout_height="160dip" android:layout_marginTop="20dip"></Button>
        <Button android:text="@+id/Button03" android:layout_below="@+id/Button01" android:id="@+id/Button03"
            android:layout_alignLeft="@+id/Button01" android:layout_height="160dip" android:layout_width="160dip"></Button>
        <Button android:text="@+id/Button04" android:layout_below="@+id/Button01" android:id="@+id/Button04"
            android:layout_toRightOf="@+id/Button03" android:layout_height="160dip" android:layout_width="160dip"></Button>
        <Button android:text="@+id/Button02" android:id="@+id/Button02" android:layout_width="wrap_content"
            android:layout_toRightOf="@+id/Button01" android:layout_alignTop="@+id/Button01" android:layout_alignParentRight="true" android:layout_height="160dip"></Button>


</RelativeLayout>

</ViewFlipper>

alt text

Reflog
can you give an example?
Mannaz
i think you misunderstood me - my goal was not the alignance (which was already working) but the scaling of the buttons. I want every row of two buttons be as wide as the screen is, so your answer isnt the right one. sry.
Mannaz
i've revised the example...
Reflog
sorry but setting the with to an absolute size doesnt work for me - it has to be screen size/orientation independent
Mannaz
+1  A: 

import android.content.Context; import android.util.AttributeSet; import android.widget.LinearLayout;

public class SquareLayout extends LinearLayout {

public SquareLayout(Context context) {
    super(context);
}

public SquareLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);

    if (width > (int)(mScale * height + 0.5)) {
        width = (int)(mScale * height + 0.5);
    } else {
        height = (int)(width / mScale + 0.5);
    }

    super.onMeasure(
            MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
    );
}

}

Jan Němec
This worked great for me. Thanks!
Nick