Android开发学习笔记一:Android启动界面的简单实现

使用窗口主题直接设置背景图片,使用"图层"资源实现多个图片叠加成一个启动图片.
示例:新浪微博启动界面
步骤一:
在res/drawable目录下创建一个splash.xml文件,同时准备dragon.png、splash_bottom.png和dragon_year.png这3个图片.
splash.xml内容如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/dragon_year"/>
<!-- 离顶端30dp -->
<item android:top="30dp">
<bitmap
    android:gravity="top"
    android:src="@drawable/dragon"/>
</item>
<item>
<bitmap
    android:gravity="bottom"
    android:src="@drawable/splash_bottom"/>
</item>
</layer-list>


注:"图层"资源要使用<layer-list>标签,其中每一个图像要放在一个<item>中。

步骤二:
在res/values目录下创建styles.xml文件,内容如下:
<style name="Theme.Splash" parent="android:Theme">
<!-- 将图层资源作为背景图像 -->
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>

步骤三:
由于在styles.xml文件中设置了全屏,所以在主界面出现前,应该设置为非全屏显示.代码如下:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
步骤四:

修改AndroidManifest.xml文件.

 <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name=".LinearLayoutActivity"
            android:label="@string/app_name" 
            android:theme="@style/Theme.Splash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
运行结果:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值