Reputation: 6867
I'm facing a strange issue in my project when creating a simple xml design as follow:
<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"/>
Now see the difference, this is the view in 4.2.2 :
And this one in 2.3.3:
Would appreciate if someone can help me with it. thanks
Upvotes: 10
Views: 853
Reputation: 1792
I have faced the same issue, in my case I had something like this
<?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>
My problem was solved changing
android:layout_margin="@dimen/lateral_margin" >
with:
android:padding="@dimen/lateral_margin" >
It seems androids 2.3.3 and lower were computing the margin differently than android 4 and greater. Now all of them behave the same way.
In your case, maybe setting the black layouts margin as padding could help.
Upvotes: 0
Reputation: 72563
It works, if you change it to this:
<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>
(I think I know why it behaves like this, let me just check something. I'll add an explanation later on)
Upvotes: 3