gpt4 book ai didi

java - 如何在LayerList android的中心添加图像

转载 作者:太空狗 更新时间:2023-10-29 16:12:06 26 4
gpt4 key购买 nike

我正在为我的初始屏幕 Activity 设置样式,并且在样式中我正在添加背景渐变,现在我正在尝试在屏幕中心添加图像,实际上就在屏幕中心下方,假设在中心下方 20dp。谁能告诉我如何激活它。

我添加到 Activity 中的样式:

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">
@drawable/background_splash
</item>
<item name="android:buttonStyle">
@style/Base.Widget.AppCompat.Button.Colored
</item>
<item name="colorAccent">
@color/white
</item>
<item name="colorPrimaryDark">
@color/blue.dark
</item>
</style>

background_splash.xml: 请引用文件中的注释

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/splash_screen_gradient" />
// here I want to add Image here such that it will be we wrap_contect and
// 20dp below center of screen
</layer-list>

splash_screen_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
>
<item >
<shape>
<gradient
android:angle="270"
android:centerColor="#ff0000"
android:endColor="#00ff00"
android:startColor="#0000ff">
</gradient>
</shape>
</item>
</layer-list>

我通过在图层列表中添加位图、项目背景尝试了几种排列组合,但它没有按预期工作。我不想将它添加到布局 xml 文件中。

最佳答案

试试这个,它对我有用

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/splash_screen_gradient" />
<item android:top="20dp">
<bitmap android:src="@drawable/ic_logo"
android:gravity="center_vertical|center_horizontal" />
</item>

</layer-list>

关于java - 如何在LayerList android的中心添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43675972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com