Android干货Android UIUI效果仿写

Android定制炫酷的TB启动图

2017-05-28  本文已影响772人  void_lhf

首先解释一下TB,TB就是Transparent Background的缩写。

Transparent Background:透明背景

而TB启动界面,顾名思义,就是背景透明的启动界面。什么是背景透明的启动界面呢?一般安卓App的启动界面都是占据了整个屏幕的;而PC端的大部分软件的启动界面都是一个对话框样式的,并未占据整个屏幕,它只占据了屏幕的一小部分,看起来无疑是美观了许多。
先来一张效果图:


TB启动界面截图.png

安卓App启动界面(多看阅读):占据整个屏幕

多看阅读.png

PC软件启动界面(Photoshop CC):占据部分屏幕

Photoshop.png

而我们的TB启动界面就是让安卓App的启动界面像pc端的软件一样只占据部分屏幕:

TB启动界面截图.png

下面就是TB启动界面的制作步骤:


首先打开电脑的Android Studio,创建一个空项目TBSplashActivityTest

然后修改layout目录下的activity_main.xml文件为如下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TB启动界面主界面"/>
</LinearLayout>

MainActivity.java则保持原样,不做任何修改

接下来新建一个空Activity——SplashActivity

系统不但为我们创建了SplashActivity.java,还帮我们创建好了相应的布局文件activity_splash.xml

这时你需要将这张透明(如果保存下来的图片不透明,请到网盘下载)图片复制到res目录下的子目录drawable目录下,改名为background_img

启动图.png Paste_Image.png

接下来修改布局activity_splash.xml为如下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:gravity="center">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/background_img"/>
    </LinearLayout>

</LinearLayout>

接下来修改SplashActivity.java为如下代码:

public class SplashActivity extends AppCompatActivity
{
    Handler handler;
    Runnable runnable;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        handler = new Handler();
        runnable = new Runnable()
        {
            @Override
            public void run()
            {
                startActivity(new Intent(SplashActivity.this,MainActivity.class));
                finish();
            }
        };
        handler.postDelayed(runnable,2000);
    }
}

很显然这是一段由SplashActivity自动启动到MainActivity的代码

接下来我们打开res/values目录下的styles.xml文件
修改styles.xml代码为如下代码:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="colorPrimaryDark">@android:color/transparent</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

</resources>

打开配置文件AndroidManifest.xml
修改AndroidManifest.xml为如下代码:

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity">
        </activity>
        <activity
            android:name=".SplashActivity"
            android:theme="@style/TranslucentTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

具体的代码也就不再解释了,相信大家都能看懂。
效果如下图:

REC_2017_5_28_17_6_3.gif

相应的资源:http://pan.baidu.com/s/1hs43NHq

上一篇 下一篇

猜你喜欢

热点阅读