LinearLayout でgravity="bottom" を設定しようとしているので、その子ビューは一番下にスタックします。
問題は、Eclipse でチェックすると問題ないように見えますが、AVD で実行すると動作しないことです。重力が上に設定されているかのように機能します。
これが私のコードです:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp" >
<com.pepotegames.spotthedifferences.SquareImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom"
android:weightSum="4" >
<ImageView
android:id="@+id/stars"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/stars"
android:background="#55000000"
android:adjustViewBounds="true" />
</LinearLayout>
これはEclipseでどのように見えるか、そしてどのように動作するかです:
http://i.imgur.com/ddHJK5S.png
編集:私のSquareImageViewは拡張されたImageViewです。問題はそれとは何の関係もありません。私はすでに同じレイアウトを通常の ImageView と同じ結果でテストしました。
確認したい場合は、次のとおりです。
public class SquareImageView extends ImageView {
public SquareImageView(Context context) {
super(context);
}
public SquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
}
}