zoukankan      html  css  js  c++  java
  • Android开发 04

    今天进行LIstView头布局的编写,

    这里需要先完成头布局的XML编写:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/grey_f3f3f3">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:padding="20dp">
            <TextView
                android:id="@+id/item_mainlv_top_tvl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/money_out"/>
            <TextView
                android:id="@+id/item_mainlv_top_tv_out"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="¥ 0"
                android:layout_below="@id/item_mainlv_top_tvl"
                android:textSize="26sp"
                android:textStyle="bold"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:textColor="@color/black"/>
            <ImageView
                android:id="@+id/item_mainlv_top_iv_hide"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:src="@mipmap/ih_show"
                android:layout_alignTop="@id/item_mainlv_top_tv_out"/>
            <TextView
                android:id="@+id/item_mainlv_top_tv2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/money_in"
                android:layout_below="@id/item_mainlv_top_tv_out"/>
            <TextView
                android:id="@+id/item_mainlv_top_tv_in"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/black"
                android:text="¥ 0"
                android:layout_below="@id/item_mainlv_top_tv_out"
                android:layout_toRightOf="@id/item_mainlv_top_tv2"
                android:layout_marginLeft="5dp"/>
            <TextView
                android:id="@+id/item_mainlv_top_tv_budget"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="¥ 0"
                android:textColor="@color/black"
                android:layout_alignParentRight="true"
                android:layout_alignBottom="@id/item_mainlv_top_tv2"
                android:layout_marginLeft="5dp"/>
            <TextView
                android:id="@+id/item_mainlv_top_tv3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/budget"
                android:layout_toLeftOf="@id/item_mainlv_top_tv_budget"
                android:layout_alignBottom="@id/item_mainlv_top_tv2"/>
            <TextView
                android:id="@+id/item_mainlv_top_lv4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableLeft="@mipmap/ih_biaoge"
                android:layout_below="@id/item_mainlv_top_tv2"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="20dp"
                android:text="@string/see_excel"
                android:textColor="@color/green_006400"
                android:drawablePadding="10dp"
                />
        </RelativeLayout>
        <TextView
            android:id="@+id/item_mainlv_top_tv_day"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="今日支出 ¥0 收入 ¥0"
            android:textStyle="bold"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="10dp"/>
    </LinearLayout>

    效果:

     然后在MainActivity中进行头布局的添加:

       private void addVHeaderView() {
            headerView = getLayoutInflater().inflate(R.layout.item_mainlv_top, null);
            todaylv.addHeaderView(headerView);//注意使用的方法
            topOutTv=headerView.findViewById(R.id.item_mainlv_top_tv_out);
            topInTv=headerView.findViewById(R.id.item_mainlv_top_tv_in);
            topbudgetTv=headerView.findViewById(R.id.item_mainlv_top_tv_budget);
            topConTv=headerView.findViewById(R.id.item_mainlv_top_tv_day);
            topShowIv=headerView.findViewById(R.id.item_mainlv_top_iv_hide);
    
            topbudgetTv.setOnClickListener(this);
            headerView.setOnClickListener(this);
            topShowIv.setOnClickListener(this);
        }

    GitHub:https://github.com/hutoob/AccountBook

    学习地址:

    https://www.bilibili.com/video/BV1Ey4y1k73N

    作者:哦心有
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    shell读取或者修改ini文件
    Linux--查询文件的第几行到第几行命令
    python读写修改配置文件(ini)
    Django REST framework 的TokenAuth认证及外键Serializer基本实现
    vue2.0+webpack+vuerouter+vuex+axios构建项目基础
    Zabbix 监控Windows磁盘IO
    磁盘 I/O 性能监控指标和调优方法
    linux查看与修改交换内存配置(解决zabbix-agent启动报错)
    js中的Map对象的简单示例
    Idea 怎么远程debug
  • 原文地址:https://www.cnblogs.com/haobox/p/14406814.html
Copyright © 2011-2022 走看看