私は、正方形のレイアウトのために自分のクラスを作成していない:カスタムSquare LinearLayout。どうやって?
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);
}
その後、私のxmlに:私のJavaコードで書かれた多くの
...
<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>
...
何も。 代わりに私のレイアウトと私のイメージが白い矩形だけを参照しています...
私は間違っていますか?
オープニングタグとしてバージョン番号を調整して追加することを忘れないでください - ' ' ??? –
Simon
修正済み:-)ありがとうございます。 – Geltrude
これはhttp://www.gadgetsaint.com/tips/dynamic-square-rectular-layouts-android/#.WRRjMvl96Hs – ASP