一個大型新聞app的骨架(android)

前端做著太枯燥了尊残,最近使勁折騰android,又因為曾經(jīng)待過一家公司是做新聞app的,所以對新聞類app特別執(zhí)著。折騰reactnative,flutter,android時,UI都是模仿這種新聞類。

先來看一下效果

android.gif

看這效果睦尽,順便參考了掘金的結構。

來看一下實現(xiàn)思路

先做沉侵式處理

 <item name="android:windowTranslucentStatus">true</item>

底部導航是用官方的組件BottomNavigationView

 <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

這個比較簡單型雳,構建項目的時候当凡,選擇BottomNavigationView就行了,簡單的操作纠俭。沿量。。

BottomNavigationView的第一個fragment冤荆,有一個頂部tab導航欄朴则,實現(xiàn)方案為TabLayout+ViewPager+Fragment

<android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:paddingTop="10dp"
        android:background="#fa1515"
        app:tabIndicatorColor="#66ff33"
        app:tabIndicatorHeight="2dp"
        app:tabTextColor="#f0b4b4"
        app:tabSelectedTextColor="#ffffff"
        app:tabMode="scrollable"
        app:tabTextAppearance="@style/TabLayoutStyle"
        />


    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_weight="1"/>

這里會出現(xiàn)fragment嵌套fragment,為了避免出現(xiàn)滑動沖突钓简,重寫ViewPager

public class NoScrollViewPager extends ViewPager {
    public NoScrollViewPager(Context context) {
        super(context);
    }
    public NoScrollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return false;
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false;
    }

}

然后layout中

<com.htyy.yutao.myapplication1.NoScrollViewPager
        android:id="@+id/main_viewpager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9" />

因為是自定義頂部導航欄乌妒,所以把ActionBar隱藏,并且自定義導航欄時注意下高度和padding-top

getSupportActionBar().hide();//隱藏掉整個ActionBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:scrollbars="none"

activity的跳轉就簡單了外邓,就是一個簡單的intent

 Intent intent =new Intent(getActivity(),Main3Activity.class);
                startActivity(intent);

另一個新的activty用的是官方的側滑DrawerLayout控件撤蚊,在項目內(nèi)新建一個DrawerLayout的activty就行了。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    <ImageView
        android:id="@+id/img_show"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" />
    <include
        layout="@layout/app_bar_main3"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main3"
        app:menu="@menu/activity_main3_drawer" />

</android.support.v4.widget.DrawerLayout>

=============

還有一些簡單的操作损话,比如webview... ... 大家可前往github查看
源碼

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末侦啸,一起剝皮案震驚了整個濱河市槽唾,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌光涂,老刑警劉巖庞萍,帶你破解...
    沈念sama閱讀 219,539評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異忘闻,居然都是意外死亡钝计,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評論 3 396
  • 文/潘曉璐 我一進店門齐佳,熙熙樓的掌柜王于貴愁眉苦臉地迎上來葵蒂,“玉大人,你說我怎么就攤上這事重虑。” “怎么了秦士?”我有些...
    開封第一講書人閱讀 165,871評論 0 356
  • 文/不壞的土叔 我叫張陵缺厉,是天一觀的道長。 經(jīng)常有香客問我隧土,道長提针,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,963評論 1 295
  • 正文 為了忘掉前任曹傀,我火速辦了婚禮辐脖,結果婚禮上,老公的妹妹穿的比我還像新娘皆愉。我一直安慰自己嗜价,他們只是感情好,可當我...
    茶點故事閱讀 67,984評論 6 393
  • 文/花漫 我一把揭開白布幕庐。 她就那樣靜靜地躺著久锥,像睡著了一般。 火紅的嫁衣襯著肌膚如雪异剥。 梳的紋絲不亂的頭發(fā)上瑟由,一...
    開封第一講書人閱讀 51,763評論 1 307
  • 那天,我揣著相機與錄音冤寿,去河邊找鬼歹苦。 笑死,一個胖子當著我的面吹牛督怜,可吹牛的內(nèi)容都是我干的殴瘦。 我是一名探鬼主播,決...
    沈念sama閱讀 40,468評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼号杠,長吁一口氣:“原來是場噩夢啊……” “哼痴施!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤辣吃,失蹤者是張志新(化名)和其女友劉穎动遭,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體神得,經(jīng)...
    沈念sama閱讀 45,850評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡厘惦,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,002評論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了哩簿。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片宵蕉。...
    茶點故事閱讀 40,144評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖节榜,靈堂內(nèi)的尸體忽然破棺而出羡玛,到底是詐尸還是另有隱情,我是刑警寧澤宗苍,帶...
    沈念sama閱讀 35,823評論 5 346
  • 正文 年R本政府宣布稼稿,位于F島的核電站,受9級特大地震影響讳窟,放射性物質(zhì)發(fā)生泄漏让歼。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,483評論 3 331
  • 文/蒙蒙 一丽啡、第九天 我趴在偏房一處隱蔽的房頂上張望谋右。 院中可真熱鬧,春花似錦补箍、人聲如沸改执。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,026評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽天梧。三九已至,卻和暖如春霞丧,著一層夾襖步出監(jiān)牢的瞬間呢岗,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,150評論 1 272
  • 我被黑心中介騙來泰國打工蛹尝, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留后豫,地道東北人。 一個月前我還...
    沈念sama閱讀 48,415評論 3 373
  • 正文 我出身青樓突那,卻偏偏與公主長得像挫酿,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子愕难,可洞房花燭夜當晚...
    茶點故事閱讀 45,092評論 2 355

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