【发布时间】:2013-09-27 01:38:47
【问题描述】:
我试图在 LinearLayout 上设置重力 =“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());
}
}
【问题讨论】:
-
是 FrameLayout 必须为您的布局,如果现在您应该切换到 RelativeLayout 以获得更好的对齐。
-
其实是这样,因为我需要星星来渲染图像上方。在这里你可以看到一个最终外观的示例:puu.sh/4kKq9.jpg 这个 Layout 在 GridView 内部使用
标签: android eclipse android-linearlayout layout-gravity