Android 仿當(dāng)樂游戲詳情頁面(一)


前段時(shí)間接到了這樣一個(gè)需求瞄沙,要求實(shí)現(xiàn)一個(gè)和當(dāng)樂游戲詳情界面類似的界面己沛;這是當(dāng)樂游戲詳情頁面的效果!距境!


當(dāng)樂游戲詳情頁

經(jīng)過一段時(shí)間的摸索申尼,爬過不少坑后,該界面總算是被實(shí)現(xiàn)出來了...


公司的效果

層次結(jié)構(gòu)

玩了幾次當(dāng)樂的界面后垫桂,發(fā)現(xiàn)其實(shí)當(dāng)樂的界面并不難實(shí)現(xiàn)晶姊。首先從UI布局層次結(jié)構(gòu)入手,該頁面是由3種處在不同層次的View組合而成伪货,然后通過中間層View的移動(dòng)進(jìn)而改變界面的顯示狀態(tài)们衙,以達(dá)到動(dòng)態(tài)的效果。</br>
通過觀察碱呼,該頁面分為3個(gè)不同的層次:

  1. 處于最底層的蒙挑,不會(huì)動(dòng)的View,該View用于顯示游戲截圖愚臀。
  2. 處于中間層的忆蚀,會(huì)移動(dòng)的View,該View用于展示游戲詳情姑裂,該View由兩個(gè)部分組成馋袜,一個(gè)是用來展示游戲簡介的內(nèi)容頭部分View,也就是游戲圖標(biāo)所在的部分舶斧;另外一個(gè)是用來展示和游戲相關(guān)的內(nèi)容信息的View欣鳖,也就是當(dāng)樂可以進(jìn)行滑動(dòng)的ViewPage。
  3. 處于最頂層的茴厉,toolbar 和底部工具欄 所處在的層次</br>

層次結(jié)構(gòu)如圖所示:</br>


層次結(jié)構(gòu)
  • 綠色部分表是的處于底部的View泽台,也就是用來展示游戲截圖的部分什荣。
  • 黃色表示的是中間層,用來展示游戲詳情及其和游戲相關(guān)的內(nèi)容怀酷。
  • 藍(lán)色表和紅色分別表示Toolbar 和 bottom Bar稻爬。

通過這層次結(jié)構(gòu)的分析,便能很容易寫出這種效果的界面蜕依。下面將開始實(shí)現(xiàn)布局代碼桅锄。

界面布局代碼

界面的布局代碼由幾個(gè)部分組成

用來展示游戲簡介的布局

游戲簡介布局

如上圖所示,以下代碼便是為了實(shí)現(xiàn)上圖的效果样眠。

<?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>
布局的最終效果

用于展示游戲詳情的信息的布局

游戲相關(guān)信息的布局

如上圖所示竞滓,以下代碼便是要實(shí)現(xiàn)上面的效果,該部分由游戲簡介的信息及其和游戲相關(guān)的信息(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>

這個(gè)界面由兩個(gè)部分組成商佑,一個(gè)是我上面已經(jīng)編寫的用于展示游戲簡介的View,在代碼里面厢塘,通過了include 將其加載了進(jìn)來茶没;</br>
另外一個(gè)部分是用于展示和游戲相關(guān)的信息的界面(如,游戲評(píng)論晚碾、游戲評(píng)測抓半、游戲禮包等等東西),在當(dāng)樂的界面里面格嘁,用戶進(jìn)行滑動(dòng)實(shí)現(xiàn)不同界面的切換笛求,由此,便可以猜的到糕簿,類似于游戲評(píng)論探入、游戲評(píng)測的界面,必定是一個(gè)Fragment懂诗,然后通過ViewPager作為容器蜂嗽,填充不同的Fragment;最后殃恒,當(dāng)用戶進(jìn)行滑動(dòng)時(shí)植旧,便能切換不同的頁面。

toolbar 布局

由于滑動(dòng)時(shí)需要?jiǎng)討B(tài)設(shè)置Toolbar的透明度离唐,所有需要自己手動(dòng)創(chuàng)建一個(gè)簡單的工具欄病附。</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>

主界面的代碼實(shí)現(xiàn)

接下來便是將上面的幾個(gè)View組合起來亥鬓,進(jìn)而實(shí)現(xiàn)當(dāng)樂游戲詳情界面的基本布局完沪。</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>

為來實(shí)現(xiàn)層次效果的,需要使用到RelativeLayout進(jìn)行布局贮竟,通過RelativeLayout的特性:當(dāng)你不指定各個(gè)View的相對(duì)位置時(shí)丽焊,寫在前面的View將被系統(tǒng)繪制在布局的最底層较剃;和棧的有點(diǎn)相似咕别。</br>

  • 所以在該布局里面技健,首先編寫id為img_vpViewPager,該View便是用于展示游戲截圖的View惰拱。
  • 接下來便是編寫用于展示游戲簡介及其和游戲相關(guān)內(nèi)容的View雌贱,<include layout="@layout/layout_content"/> 代碼便是將我們上面寫的游戲展示信息的View加載進(jìn)去了。
  • 最后便是加載ToolBar<include layout="@layout/layout_bar"/>

這是我們現(xiàn)在的效果

當(dāng)然偿短,當(dāng)這僅僅只是一個(gè)界面欣孤,并不能像當(dāng)樂一樣對(duì)界面進(jìn)行移動(dòng)。接下來昔逗,便需要開始編寫布局移動(dòng)的邏輯了降传。


布局最終效果

Android 仿當(dāng)樂游戲詳情頁(二)

android 仿當(dāng)樂游戲詳情頁面(三)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市勾怒,隨后出現(xiàn)的幾起案子婆排,更是在濱河造成了極大的恐慌,老刑警劉巖笔链,帶你破解...
    沈念sama閱讀 217,907評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件段只,死亡現(xiàn)場離奇詭異,居然都是意外死亡鉴扫,警方通過查閱死者的電腦和手機(jī)赞枕,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,987評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來坪创,“玉大人炕婶,你說我怎么就攤上這事±吃ぃ” “怎么了古话?”我有些...
    開封第一講書人閱讀 164,298評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長锁施。 經(jīng)常有香客問我陪踩,道長,這世上最難降的妖魔是什么悉抵? 我笑而不...
    開封第一講書人閱讀 58,586評(píng)論 1 293
  • 正文 為了忘掉前任肩狂,我火速辦了婚禮,結(jié)果婚禮上姥饰,老公的妹妹穿的比我還像新娘傻谁。我一直安慰自己,他們只是感情好列粪,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,633評(píng)論 6 392
  • 文/花漫 我一把揭開白布审磁。 她就那樣靜靜地躺著谈飒,像睡著了一般。 火紅的嫁衣襯著肌膚如雪态蒂。 梳的紋絲不亂的頭發(fā)上杭措,一...
    開封第一講書人閱讀 51,488評(píng)論 1 302
  • 那天,我揣著相機(jī)與錄音钾恢,去河邊找鬼手素。 笑死,一個(gè)胖子當(dāng)著我的面吹牛瘩蚪,可吹牛的內(nèi)容都是我干的泉懦。 我是一名探鬼主播,決...
    沈念sama閱讀 40,275評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼疹瘦,長吁一口氣:“原來是場噩夢啊……” “哼崩哩!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起言沐,我...
    開封第一講書人閱讀 39,176評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤邓嘹,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后呢灶,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體吴超,經(jīng)...
    沈念sama閱讀 45,619評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,819評(píng)論 3 336
  • 正文 我和宋清朗相戀三年鸯乃,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了鲸阻。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,932評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡缨睡,死狀恐怖鸟悴,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情奖年,我是刑警寧澤细诸,帶...
    沈念sama閱讀 35,655評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站陋守,受9級(jí)特大地震影響震贵,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜水评,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,265評(píng)論 3 329
  • 文/蒙蒙 一猩系、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧中燥,春花似錦寇甸、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,871評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽吟秩。三九已至,卻和暖如春绽淘,著一層夾襖步出監(jiān)牢的瞬間涵防,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,994評(píng)論 1 269
  • 我被黑心中介騙來泰國打工收恢, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留武学,地道東北人祭往。 一個(gè)月前我還...
    沈念sama閱讀 48,095評(píng)論 3 370
  • 正文 我出身青樓伦意,卻偏偏與公主長得像,于是被迫代替她去往敵國和親硼补。 傳聞我的和親對(duì)象是個(gè)殘疾皇子驮肉,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,884評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,127評(píng)論 25 707
  • 在上一篇文章里面,基本上算是實(shí)現(xiàn)了該效果的布局已骇,有了布局离钝,接下來就要對(duì)布局進(jìn)行移動(dòng)處理。 android 仿當(dāng)樂游...
    dorn19978閱讀 1,039評(píng)論 0 11
  • 在上兩篇文章中褪储,我們已經(jīng)實(shí)現(xiàn)了基本的界面的布局和移動(dòng)效果卵渴,但是mImgShotView、mContentView卻...
    dorn19978閱讀 1,351評(píng)論 6 27
  • 內(nèi)容抽屜菜單ListViewWebViewSwitchButton按鈕點(diǎn)贊按鈕進(jìn)度條TabLayout圖標(biāo)下拉刷新...
    皇小弟閱讀 46,759評(píng)論 22 665
  • 晚上鲤竹,舍友無聊就外放了許多老歌浪读。當(dāng)《倩女幽魂》那熟悉的旋律響起時(shí),我們都不由得感慨還是老歌有味道辛藻。但提起哥哥張國榮...
    囈語浮生閱讀 237評(píng)論 0 0