tworzę moje własne klasy dla układu kwadratowy:Niestandardowy kwadrat LinearLayout. W jaki sposób?
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);
}
Następnie w moim 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>
...
nic więcej napisane w moim kodu java. Ale zamiast tego, jeśli mój układ i mój obraz, widzę tylko biały prostokąt ...
Co jest nie tak?
tag otwarciem - ' ' ??? –
Simon
poprawiono :-) Dziękuję. – Geltrude
To może pomóc http://www.gadgetsaint.com/tips/dynamic-square-rectangular-layouts-android/#.WRRjMvl96Hs – ASP