Android 仿当乐游戏详情页面(一)


前段时间接到了这样一个需求,要求实现一个和当乐游戏详情界面类似的界面;这是当乐游戏详情页面的效果!!


当乐游戏详情页

经过一段时间的摸索,爬过不少坑后,该界面总算是被实现出来了...


公司的效果

层次结构

玩了几次当乐的界面后,发现其实当乐的界面并不难实现。首先从UI布局层次结构入手,该页面是由3种处在不同层次的View组合而成,然后通过中间层View的移动进而改变界面的显示状态,以达到动态的效果。</br>
通过观察,该页面分为3个不同的层次:

  1. 处于最底层的,不会动的View,该View用于显示游戏截图。
  2. 处于中间层的,会移动的View,该View用于展示游戏详情,该View由两个部分组成,一个是用来展示游戏简介的内容头部分View,也就是游戏图标所在的部分;另外一个是用来展示和游戏相关的内容信息的View,也就是当乐可以进行滑动的ViewPage。
  3. 处于最顶层的,toolbar 和底部工具栏 所处在的层次</br>

层次结构如图所示:</br>


层次结构
  • 绿色部分表是的处于底部的View,也就是用来展示游戏截图的部分。
  • 黄色表示的是中间层,用来展示游戏详情及其和游戏相关的内容。
  • 蓝色表和红色分别表示Toolbar 和 bottom Bar。

通过这层次结构的分析,便能很容易写出这种效果的界面。下面将开始实现布局代码。

界面布局代码

界面的布局代码由几个部分组成

用来展示游戏简介的布局

游戏简介布局

如上图所示,以下代码便是为了实现上图的效果。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/head"
    android:layout_width="match_parent"
    android:layout_height="@dimen/game_detail_head_height">

    <View
        android:id="@+id/temp"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/transparent" />

    <me.relex.circleindicator.CircleIndicator
        android:id="@+id/indicator"
        android:layout_width="match_parent"
        android:layout_height="@dimen/game_detail_head_indicator_height"
        android:gravity="center" />

    <RelativeLayout
        android:id="@+id/head_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/temp"
        android:background="@color/white">

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="130dp"
            android:layout_marginTop="8dp"
            android:text="游戏名"
            android:textColor="@color/text_black_color"
            android:textSize="@dimen/text_larger" />

        <TextView
            android:id="@+id/detail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/name"
            android:layout_below="@+id/name"
            android:text="角色扮演"
            android:textColor="@color/text_gray_color"
            android:textSize="@dimen/text_medium" />

        <TextView
            android:id="@+id/feature"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/name"
            android:layout_below="@+id/detail"
            android:text="特性111111"
            android:textColor="@color/text_gray_color"
            android:textSize="@dimen/text_medium" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_alignParentBottom="true"
            android:background="@color/line_color" />
    </RelativeLayout>

    <View
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_alignBottom="@+id/icon"
        android:layout_alignParentRight="true"
        android:visibility="gone" />

    <ImageView
        android:id="@+id/icon"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="10dp"
        android:src="@mipmap/default_icon" />
</RelativeLayout>
布局的最终效果

用于展示游戏详情的信息的布局

游戏相关信息的布局

如上图所示,以下代码便是要实现上面的效果,该部分由游戏简介的信息及其和游戏相关的信息(Viewpage)组合而成。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/game_detail_bar"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <include
        layout="@layout/layout_game_detail_head"
        android:layout_width="match_parent"
        android:layout_height="@dimen/game_detail_head_height" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab"
        style="@style/TabLayoutStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/line_color" />

    <android.support.v4.view.ViewPager
        android:id="@+id/content_vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

这个界面由两个部分组成,一个是我上面已经编写的用于展示游戏简介的View,在代码里面,通过了include 将其加载了进来;</br>
另外一个部分是用于展示和游戏相关的信息的界面(如,游戏评论、游戏评测、游戏礼包等等东西),在当乐的界面里面,用户进行滑动实现不同界面的切换,由此,便可以猜的到,类似于游戏评论、游戏评测的界面,必定是一个Fragment,然后通过ViewPager作为容器,填充不同的Fragment;最后,当用户进行滑动时,便能切换不同的页面。

toolbar 布局

由于滑动时需要动态设置Toolbar的透明度,所有需要自己手动创建一个简单的工具栏。</br>
以下代码便是Toolbar的具体布局.。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/game_detail_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/tool_bar_height"
    android:fitsSystemWindows="true">

    <View
        android:id="@+id/bar_bg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary" />

    <TextView
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:onClick="onClick"
        android:paddingLeft="-5dp"
        android:paddingRight="8dp"
        android:text="test"
        android:textColor="#fff"
        android:textSize="16sp" />

    <ImageView
        android:id="@+id/download_manager"
        style="@style/BarImgStyle"
        android:layout_alignParentRight="true"
        android:onClick="onClick"
        android:scaleType="fitCenter"
        android:src="@mipmap/icon_download" />

</RelativeLayout>

主界面的代码实现

接下来便是将上面的几个View组合起来,进而实现当乐游戏详情界面的基本布局。</br>
代码如下:

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

    <android.support.v4.view.ViewPager
        android:id="@+id/img_vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <include layout="@layout/layout_content"/>

    <View
        android:id="@+id/state_bar_temp"
        android:layout_width="match_parent"
        android:layout_height="@dimen/state_bar_height"
        android:background="@color/colorPrimary"/>

    <include
        layout="@layout/layout_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/tool_bar_height"/>
</RelativeLayout>

为来实现层次效果的,需要使用到RelativeLayout进行布局,通过RelativeLayout的特性:当你不指定各个View的相对位置时,写在前面的View将被系统绘制在布局的最底层;和栈的有点相似。</br>

  • 所以在该布局里面,首先编写id为img_vpViewPager,该View便是用于展示游戏截图的View。
  • 接下来便是编写用于展示游戏简介及其和游戏相关内容的View,<include layout="@layout/layout_content"/> 代码便是将我们上面写的游戏展示信息的View加载进去了。
  • 最后便是加载ToolBar<include layout="@layout/layout_bar"/>

这是我们现在的效果

当然,当这仅仅只是一个界面,并不能像当乐一样对界面进行移动。接下来,便需要开始编写布局移动的逻辑了。


布局最终效果

Android 仿当乐游戏详情页(二)

android 仿当乐游戏详情页面(三)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,015评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,262评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,727评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,986评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,363评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,610评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,871评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,582评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,297评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,551评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,053评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,385评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,035评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,079评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,841评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,648评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,550评论 2 270

推荐阅读更多精彩内容