DCo*_*der 2 java android android-layout android-xml android-styles
我正在为初始屏幕活动设置样式,并在样式中添加背景渐变,现在我试图在屏幕中心添加图像,实际上是在屏幕中心下方,比如说在中心下方20dp。谁能告诉我如何激活它。
我为活动添加的样式:
<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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我已尝试通过在图层列表中添加位图,项目背景来尝试几种排列组合,但其无法正常工作。我不想将其添加到布局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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3090 次 |
| 最近记录: |