2011-07-11 12 views
7

imは正方形のimageviewsで表を作成しようとしています(サイズも同じです)。問題は、画像の高さと幅が違うことです。 テーブルは3x3で、私は次のようにしたい: 各セルには画面幅の1/3(多分レイアウトの重み?)と高さ=幅 がある。コード内のxml。 レイアウトの重み=(事前に おかげで、Android square imageview

答えて

4

とイムnoobのはscaleType属性を試しているので、それを説明してください。あなたがcenterCropをしたいと思います。

1

だけでなく、あなたも、各画像を圧迫するscaleType = fitXYを使用することができますImageViewの寸法のimageveiwはきれいな解決策になるかもしれない拡張

1

にこれは私の作品:。

public class Icon extends ImageView { 

public Icon(final Context context) { 
    super(context); 
} 

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

public Icon(final Context context, final AttributeSet attrs, 
     final int defStyle) { 
    super(context, attrs, defStyle); 
} 

@Override 
protected void onMeasure(int width, int height) { 
    super.onMeasure(width, height); 
    int measuredWidth = getMeasuredWidth(); 
    int measuredHeight = getMeasuredHeight(); 
    if (measuredWidth > measuredHeight) { 
     setMeasuredDimension(measuredHeight, measuredHeight); 
    } else { 
     setMeasuredDimension(measuredWidth, measuredWidth); 

    } 

} 

} 

とXMLで:

<com.your_package_name.Icon 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scaleType="centerCrop" 
    android:src="@drawable/screen" />