Я хочу сделать расположение подобным этому:
www.ImageBanana.net - layout.png http://www.imagebanana.com/img/9kmlhy66/thumb/layout.png
Четыре квадратных кнопки на экране - каждый из тех, которые используют половину экрана с/экран высотой (какой бы ни меньше). Независимый от размера экрана / разрешение.
Я уже попытался достигнуть этого при помощи a LinearLayout
но кнопки заканчивают тем, что использовали корректную ширину, но все еще имели высоту фона (не квадратный больше).
Это похоже на это: www.ImageBanana.net - layout2.png http://www.imagebanana.com/img/i2ni6g4/thumb/layout2.png
Как я могу достигнуть Расположения для сходства с изображением наверху выше?
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class SquareLayout extends LinearLayout {
// Desired width-to-height ratio - 1.0 for square
private final double mScale = 1.0;
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)
);
}
}
хорошо, вот измененный пример:
<?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>