依赖
//OkHttp,get请求依赖 implementation 'com.squareup.okhttp3:okhttp:3.4.1' implementation 'com.squareup.okio:okio:1.5.0' //recyclerview依赖 implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.jcodecraeer:xrecyclerview:1.2.0' implementation 'com.google.code.gson:gson:2.2.4' //fresco图片加载依赖 implementation 'com.facebook.fresco:fresco:0.12.0'
//RXjava2 implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' implementation 'io.reactivex.rxjava2:rxjava:2.1.7' implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' //Retrofit网络请求依赖 implementation 'com.squareup.retrofit2:retrofit:2.4.0' implementation 'com.squareup.retrofit2:converter-gson:2.4.0' implementation 'com.xhb:xbanner:1.2.2' implementation 'com.github.bumptech.glide:glide:3.7.0' implementation 'com.android.support:support-v4:27.1.1'
权限
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- 读取网络状态的权限 --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
android:name=".MyApplication"
首页布局
activity_main.xml
<LinearLayout 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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="55dp" android:background="#bdbd"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#fff" android:layout_centerInParent="true" android:textSize="18dp" android:text="首页"/> </RelativeLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fr"></FrameLayout> </LinearLayout>
fragment1.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.jcodecraeer.xrecyclerview.XRecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/xrc"></com.jcodecraeer.xrecyclerview.XRecyclerView> </RelativeLayout>
shouye_jiugongge.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:orientation="vertical"> <com.facebook.drawee.view.SimpleDraweeView android:layout_gravity="center_horizontal" android:layout_width="70px" android:layout_height="70px" android:id="@+id/sd"></com.facebook.drawee.view.SimpleDraweeView> <TextView android:textSize="20px" android:text="横向滑动" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:id="@+id/jiugongge_tv"/> </LinearLayout>
shouye_tuijian.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#aaa"> <TextView android:textSize="25px" android:layout_width="match_parent" android:layout_marginTop="8dp" android:layout_height="30dp" android:gravity="center_horizontal" android:text="推荐" android:id="@+id/shouye_tuijian_tv"/> </LinearLayout> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/shouye_tuijian_rc"></android.support.v7.widget.RecyclerView> </LinearLayout>
shouye_tuijian_zi.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#aaa"> <TextView android:textSize="25px" android:layout_width="match_parent" android:layout_marginTop="8dp" android:layout_height="30dp" android:gravity="center_horizontal" android:text="推荐" android:id="@+id/shouye_tuijian_tv"/> </LinearLayout> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/shouye_tuijian_rc"></android.support.v7.widget.RecyclerView> </LinearLayout>
shouye_xbanner.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <com.stx.xhb.xbanner.XBanner android:layout_width="match_parent" android:layout_height="220px" app:AutoPlayTime="2000" android:id="@+id/myxbanner"></com.stx.xhb.xbanner.XBanner> </LinearLayout>shouyemiaosha_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:orientation="horizontal"> <TextView android:textColor="#ff0000" android:textSize="20px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/shouue_miaosha_tv"/> <TextView android:layout_gravity="center_vertical" android:textSize="18px" android:id="@+id/shouue_miaosha_tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="60px" /> <LinearLayout android:layout_gravity="center_vertical" android:layout_marginLeft="50px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/tv_hour" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:paddingTop="3dp" android:paddingBottom="3dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:background="#000000" android:textColor="@android:color/white" android:textSize="12sp" android:text="02"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:textStyle="bold" android:textColor="@android:color/black" android:text=":"/> <TextView android:background="#000000" android:id="@+id/tv_minute" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:paddingTop="3dp" android:paddingBottom="3dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:textColor="@android:color/white" android:textSize="12sp" android:text="15"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:textStyle="bold" android:textColor="@android:color/black" android:text=":"/> <TextView android:background="#000000" android:id="@+id/tv_second" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:paddingTop="3dp" android:paddingBottom="3dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:textColor="@android:color/white" android:textSize="12sp" android:text="36"/> </LinearLayout> </LinearLayout> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/miaosha_rv"></android.support.v7.widget.RecyclerView> </LinearLayout>
shouyerc.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/shouye_rc"></android.support.v7.widget.RecyclerView> <LinearLayout android:layout_marginTop="30px" android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:textSize="25px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@android:color/black" android:layout_marginTop="5dp" android:text="京东"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="快报" android:background="#ff0000"