问题
I would like to use a splah screen containing 2 images:
- the main image must be fully center
- the secondary image must be center between the bottom and the main image
The expected render is something like this:
But I don't see how to get this, and my second image is bottom aligned:
The XML of my splash is:
<?xml version="1.0" encoding="utf-8" ?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/ComplementColor" />
<padding
android:left="0dip"
android:top="0dip"
android:right="0dip"
android:bottom="0dip" />
</shape>
</item>
<item>
<bitmap android:src="@drawable/main_logo"
android:gravity="center" />
</item>
<item>
<bitmap android:src="@drawable/secondary_logo"
android:gravity="bottom" />
</item>
</layer-list>
回答1:
I've finally choose another solution close to that suggested by @Leonardo Cavazzani.
I've added a margin to the bottom image like this:
<?xml version="1.0" encoding="utf-8" ?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/ComplementColor" />
<padding
android:left="0dip"
android:top="0dip"
android:right="0dip"
android:bottom="0dip" />
</shape>
</item>
<item>
<bitmap android:src="@drawable/main_logo"
android:gravity="center" />
</item>
<item
android:bottom="40dp">
<bitmap android:src="@drawable/secondary_logo"
android:gravity="bottom" />
</item>
</layer-list>
回答2:
Set a marginBottom for your bitmap
<bitmap android:src="@drawable/secondary_logo"
android:gravity="bottom"
android:layout_marginBottom="100dp" />
回答3:
You can achieve it trough the LayoutXML instead of the Drawable.XML
A simple LayoutManager where the first image is centered and the second alignedToTheBottom of the first plus topMargin solve your problem.
来源:https://stackoverflow.com/questions/46245887/android-how-to-align-2-images-on-a-splash-screen