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

Различия в дизайнах макетов Android между версиями 2.3.3 и 4+

У меня возникла странная проблема в моем проекте при создании простого XML-проекта:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="#FF0000"
    android:layout_marginLeft="30dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button" 
        android:layout_gravity="left|center_vertical"/>

Теперь посмотрим разницу, это вид в 4.2.2:

2.3.3 version

И это в 2.3.3:

enter image description here

Был бы признателен, если кто-то может мне помочь. спасибо

4b9b3361

Ответ 1

Он работает, если вы измените его на это:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_marginLeft="30dp"
    android:background="#FF0000"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="New Button" />

</LinearLayout>

(Думаю, я знаю, почему он ведет себя так, позвольте мне просто кое-что проверить. Я добавлю объяснение позже)

Ответ 2

Я столкнулся с той же проблемой, в моем случае у меня было что-то вроде этого

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/match"
    android:background="@color/light"
    android:orientation="vertical"
    android:layout_margin="@dimen/lateral_margin" >

    <ImageView
        android:id="@+id/full_screen_image"
        style="@style/match_width"
        android:scaleType="fitCenter"
        android:layout_gravity="center"
        android:layout_weight="2"
        android:contentDescription="@string/image_content_description"/>

    <TextView
        android:id="@+id/barcode_number"
        style="@style/match_width"
        android:gravity="center"
        android:textColor="@color/dark_text"
        android:textSize="30sp"
        android:visibility="gone" />

</LinearLayout>

Моя проблема была решена с изменением

    android:layout_margin="@dimen/lateral_margin" >

с:

    android:padding="@dimen/lateral_margin" >

Кажется, андроиды 2.3.3 и ниже вычисляли разницу по-другому, чем андроид 4 и выше. Теперь все они ведут себя одинаково.

В вашем случае, возможно, задание поля макета черных в качестве дополнения может помочь.