Android 实现悬浮的几种方式(二)HeaderView显示隐藏

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

完整开源地址:https://docs.qq.com/doc/DSkNLaERkbnFoS0ZF

        <LinearLayout

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:gravity="center"

            android:orientation="vertical">



            <TextView

                android:id="@+id/tv_product_boxs"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="@string/common_null"

                android:textColor="@color/gray_32"

                android:textSize="28dp" />



            <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_marginTop="@dimen/d_10dp"

                android:text="箱"

                android:textColor="@color/gray_a"

                android:textSize="13sp" />



        </LinearLayout>



        <TextView

            android:layout_width="1dp"

            android:layout_height="match_parent"

            android:background="@color/lineColor" />



        <LinearLayout

            android:layout_width="0dp"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:gravity="center"

            android:orientation="vertical">



            <TextView

                android:id="@+id/tv_product_singles"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="@string/common_null"

                android:textColor="@color/gray_32"

                android:textSize="28dp" />



            <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_marginTop="@dimen/d_10dp"

                android:text="单标"

                android:textColor="@color/gray_a"

                android:textSize="13sp" />

        </LinearLayout>



    </LinearLayout>



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

</LinearLayout>



> header\_chart\_bottom.xml



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

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



<LinearLayout

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:background="@drawable/selector_ll_white"

    android:gravity="center"

    android:padding="@dimen/d_15dp">



    <TextView

        android:id="@+id/tv_time_details"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:drawableLeft="@mipmap/icon_boxing_40"

        android:drawablePadding="@dimen/d_10dp"

        android:gravity="center_vertical"

        android:text="今日"

        android:textColor="@color/gray_32"

        android:textSize="14sp" />



    <TextView

        android:layout_width="0dp"

        android:layout_height="wrap_content"

        android:layout_weight="1"

        android:drawablePadding="@dimen/d_10dp"

        android:gravity="center_vertical"

        android:text="生产装箱情况"

        android:textColor="@color/gray_32"

        android:textSize="14sp" />



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:drawablePadding="5dp"

        android:drawableRight="@mipmap/ic_arrow_right"

        android:text="详情"

        android:textColor="@color/gray_a"

        android:textSize="14sp" />



</LinearLayout>



> layout\_line.xml



<?xml version="1.0" encoding="utf-8"?>

<View xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width="match_parent"

android:layout_height="@dimen/height_line"

android:background="@color/lineColor" />



最后主Activity的布局:activity\_chart.xml



<?xml version="1.0" encoding="utf-8"?>

<FrameLayout 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"
<include layout="@layout/layout_recycler_view_loading" />

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



> layout\_recycler\_view\_loading.xml



<?xml version="1.0" encoding="utf-8"?>

<merge xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app="http://schemas.android.com/apk/res-auto">



<!--使用PtrClassicFrameLayout套RecyclerViewFinal-->

<cn.finalteam.loadingviewfinal.PtrClassicFrameLayout

    android:id="@+id/ptr_rv_layout"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    app:ptr_duration_to_close="300"

    app:ptr_duration_to_close_header="1500"

    app:ptr_keep_header_when_refresh="true"

    app:ptr_ratio_of_header_height_to_refresh="1.2"

    app:ptr_resistance="1.7">



    <cn.finalteam.loadingviewfinal.RecyclerViewFinal

        android:id="@+id/rv_list"

        android:layout_width="match_parent"

        android:descendantFocusability="beforeDescendants"

        android:layout_height="match_parent"

        android:cacheColorHint="#00000000"

        app:loadMoreMode="click|scroll"

        app:loadMoreView="cn.finalteam.loadingviewfinal.DefaultLoadMoreView"

        app:noLoadMoreHideView="false" />



</cn.finalteam.loadingviewfinal.PtrClassicFrameLayout>



布局定好了,剩下的就简单了。



第一步:初始化主页面View和各个HeaderView



public class StockInProductChartActivity extends StateViewActivity {



private static final int REQUEST_CODE_TIME = 1;

@Bind(R.id.rv_list)

RecyclerViewFinal mRvList;

@Bind(R.id.ptr_rv_layout)

PtrClassicFrameLayout mPtrRvLayout;

@Bind(R.id.tv_product_name)

TextView tvProductName;

@Bind(R.id.tv_product_boxs)

TextView tvProductBoxs;

@Bind(R.id.tv_product_singles)

TextView tvProductSingles;

@Bind(R.id.fl_suspend)

RelativeLayout flSuspend;



private View headerViewTop;

private View headerViewBottom;

private View suspendView;

private void initHeaderView() {

    LayoutInflater layoutInflater = LayoutInflater.from(this);

    //上方的header

    headerViewTop = layoutInflater.inflate(R.layout.header_chart_top, null);



    //悬浮的Header

    suspendView = layoutInflater.inflate(R.layout.suspend_chart, null);

    suspendViewHolder = new SuspendViewHolder();

    ButterKnife.bind(suspendViewHolder, suspendView);



    //下方的header

    headerViewBottom = layoutInflater.inflate(R.layout.header_chart_bottom, null);



    mRvList.addHeaderView(headerViewTop);

    mRvList.addHeaderView(suspendView);

    mRvList.addHeaderView(headerViewBottom);

}

//悬浮view

static class SuspendViewHolder {

    @Bind(R.id.tv_product_name)

    TextView tvProductName;

    @Bind(R.id.tv_product_boxs)

    TextView tvProductBoxs;

    @Bind(R.id.tv_product_singles)

    TextView tvProductSingles;

    //根布局

    @Bind(R.id.fl_suspend)

    RelativeLayout flSuspend;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值