Подтвердить что ты не робот

Android: layout_marginBottom, похоже, не работает должным образом в 2.2 (Froyo)

У меня есть этот блок ImageView внутри Относительного макета:

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="50dip"
    android:layout_marginLeft="81dip"
    android:src="@drawable/swipehelp"
    />

Это рисует изображение прямо там, где это ожидалось бы на экранах с нормальной и высокой плотностью на Android 1.6, однако на 2.2 он, кажется, игнорирует layout_marginBottom и всегда рисует изображение, полностью выровненное снизу. Кто-нибудь видел это раньше, и если это так, вы знаете, что исправить?

Изменить 1:

Он находится внутри RelativeLayout, объявленного таким образом:

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/excusescreen"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/woodbg">

Изменить 2:

Здесь полный код макета:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/excusescreen"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/woodbg">
   <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imlateTopBar"
    android:layout_width="fill_parent"
    android:layout_height="44dip"
    android:background="@drawable/topandbottombars"
    android:layout_alignParentTop="true"    
    >
    <ImageView
            android:id="@+id/excHomeBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dip"
            android:layout_marginTop="7dip"
            android:src="@drawable/catexcusehomebtn"
            >
    </ImageView>
    <ImageView
            android:id="@+id/excBackToCatsBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="7dip"
            android:src="@drawable/backtocats"
            >
    </ImageView>
     </LinearLayout>
     <ViewFlipper
    android:id="@+id/excuses"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dip"
     >
     </ViewFlipper>
     <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imlateTopBar"
    android:layout_width="fill_parent"
    android:layout_height="44dip"
    android:background="@drawable/topandbottombars"
    android:layout_alignParentBottom="true" 
    >
    <ImageView
        android:id="@+id/emailItBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:layout_marginTop="7dip"
        android:src="@drawable/emailit"
        >
    </ImageView>
    <TextView
        android:id="@+id/numExcusesText"
        android:layout_width="100dip"
        android:layout_height="30dip"
        android:layout_marginLeft="5dip"
        android:layout_marginTop="7dip"
        android:textColor="#66ffffff"
        android:gravity="center"
        android:textSize="18dip"
        android:textStyle="bold"
        android:text="1/13"
        >
    </TextView>
    <ImageView
        android:id="@+id/shareItBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:layout_marginTop="7dip"
        android:src="@drawable/shareit"
        >
    </ImageView>
     </LinearLayout>
     <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="50dip"
    android:layout_marginLeft="81dip"
    android:src="@drawable/swipehelp"
    />

 </RelativeLayout>

Изменить 3

alt text

4b9b3361

Ответ 1

Хорошо, поэтому после многого поиска я нашел ссылку на эту проблему, которая фактически относится к 09, но комментарии 2010 года показывают множество проблем с alignParentBottom в 2.2. http://code.google.com/p/android/issues/detail?id=1394

Итак, я сделал обходной путь, поставив все это в FrameLayout и сделал ImageView дочерним элементом вне моего RelativeLayout и разместил его с layout_gravity. Это сделал трюк и заставил его работать во всех версиях. Здесь последний код:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <RelativeLayout
    android:id="@+id/excusescreen"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/woodbg"
    android:clipChildren="true">
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imlateTopBar"
    android:layout_width="fill_parent"
    android:layout_height="44dip"
    android:background="@drawable/topandbottombars"
    android:layout_alignParentTop="true"    
    >
    <ImageView
            android:id="@+id/excHomeBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dip"
            android:layout_marginTop="7dip"
            android:src="@drawable/catexcusehomebtn"
            >
    </ImageView>
    <ImageView
            android:id="@+id/excBackToCatsBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="7dip"
            android:src="@drawable/backtocats"
            >
    </ImageView>
</LinearLayout>
<ViewFlipper
    android:id="@+id/excuses"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dip"
>
</ViewFlipper>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imlateTopBar"
    android:layout_width="fill_parent"
    android:layout_height="44dip"
    android:background="@drawable/topandbottombars"
    android:layout_alignParentBottom="true" 
    >
    <ImageView
        android:id="@+id/emailItBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:layout_marginTop="7dip"
        android:src="@drawable/emailit"
        >
    </ImageView>
    <TextView
        android:id="@+id/numExcusesText"
        android:layout_width="100dip"
        android:layout_height="30dip"
        android:layout_marginLeft="5dip"
        android:layout_marginTop="7dip"
        android:textColor="#66ffffff"
        android:gravity="center"
        android:textSize="18dip"
        android:textStyle="bold"
        android:text="1/13"
        >
    </TextView>
    <ImageView
        android:id="@+id/shareItBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:layout_marginTop="7dip"
        android:src="@drawable/shareit"
        >
    </ImageView>
    </LinearLayout>
    </RelativeLayout>
    <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|bottom"
    android:layout_marginBottom="50dip"
    android:src="@drawable/swipehelp"
    />
    </FrameLayout>

Ответ 2

В FrameLayout добавьте View со следующим:

android:id="@+id/gap"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_alignParentBottom="true"

Теперь, чтобы исправить layout_marginBottom, используйте приведенное выше:

android:layout_above="@+id/gap"

Ответ 3

То же самое было для Android 1.6 для меня, пока я не изменил layout_height на fill_parent на самый внешний RelativeLayout`

По-видимому, он не может получить границы корректно, когда настройки на wrap_content. Если нет специальной причины для того, чтобы ширина и высота RelativeLayout охватывали его содержимое, я бы сказал, укажите его так.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/excusescreen"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/woodbg"
    android:clipChildren="true">
    <!-- all the other stuff -->
</RelativeLayout>

Ответ 4

Если вы не хотите добавлять дополнительный просмотр, вы можете использовать InsetDrawable с android:insetBottom.

Ответ 5

У нас была та же проблема, и мы использовали LinearLayout, позиционированный с ParentBottom, давая это дополнение и помещая изображение/кнопку/вид внутри него. Использование маржи на цели вместо заполнения в LinearLayout также работает, а также btw.