今天看cjm9的代码时候想把模块梳理一下,顺便再熟悉下mvp,rxjava和retrofit的综合运用。我们先看图
新闻item的具体信息
图片item的具体信息
大概就是上面那样。
下面开始代码分析:
先看下分包:
下面我们看界面的布局文件:
1.fragment_explore.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/tab_height"
android:background="@color/color_primary"
android:elevation="@dimen/cardview_default_elevation"
android:gravity="center_vertical"
android:padding="5dp"
android:text="@string/explore"
android:textColor="#ffffff"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/tab_height"
android:background="@color/color_icons"
android:elevation="@dimen/cardview_default_elevation"
android:orientation="horizontal">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<net.lucode.hackware.magicindicator.MagicIndicator
android:id="@+id/magic_indicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true" />
<TextView
android:id="@+id/tv_section"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_primary_light"
android:gravity="center_vertical"
android:padding="5dp"
android:text="@string/live_exchange"
android:textColor="@color/color_icons"
android:textSize="12sp" />
<ImageView
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:alpha="0.3"
android:scaleType="centerCrop"
android:src="@drawable/background_shadow" />
</FrameLayout>
<ImageView
android:id="@+id/iv_expandable"
android:layout_width="@dimen/tab_height"
android:layout_height="@dimen/tab_height"
android:layout_weight="0"
android:background="?selectableItemBackgroundBorderless"
android:padding="8dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_expand_open" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_layout_background" />
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_layout_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_selected"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="@string/explore_drag"
android:textColor="@color/color_accent"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="@string/explore_delete"
android:textColor="@color/color_error"
android:textSize="12sp" />
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="0"
android:src="@color/color_divider" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="5dp"
android:text="点击添加更多栏目"
android:textSize="12sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_unselected"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null" />
</LinearLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>
这布局搭建很巧妙,不是通过设置Visible进行小界面的替换,而是通过动画,利用framelayout的特性进行显示和消失的。