creo la mia classe per la pianta quadrata:Custom Square LinearLayout. Come?
public class SquareLayout extends LinearLayout{
public SquareLayout(Context context) {
super(context);
}
public SquareLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SquareLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
int size = width > height ? height : width;
setMeasuredDimension(size, size);
}
Poi, nel mio xml:
...
<com.myApp.SquareLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<ImageView
android:id="@+id/cellImageView"
android:adjustViewBounds="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="2dp"
android:scaleType="centerCrop"
android:src="@drawable/image" />
</com.myApp.SquareLayout>
...
Niente di scritto più nel mio codice Java. Ma invece se il mio layout e la mia immagine, vedo solo un rettangolo bianco ...
Cosa ho sbagliato?
tag di apertura - ' ' ??? –
Simon
corretto :-) Grazie. – Geltrude
Questo potrebbe aiutare http://www.gadgetsaint.com/tips/dynamic-square-rectangular-layouts-android/#.WRRjMvl96Hs – ASP