• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > ListView添加头布局和脚布局,listview添加布局

ListView添加头布局和脚布局,listview添加布局

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了listview添加头布局,listview头布局,listview添加脚布局,listview加载不同布局,listview显示不同布局等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

ListView添加头布局和脚布局,listview添加布局


 ListView添加头布局和脚布局

 

之前学习喜马拉雅的时候做的一个小Demo,贴出来,供大家学习参考;

如果我们当前的页面有多个接口、多种布局的话,我们一般的选择无非就是1、多布局;2、各种复杂滑动布局外面套一层ScrollView(好low);3、头布局脚布局。有的时候我们用多布局并不能很好的实现,所以头布局跟脚布局就是我们最好的选择了;学过了ListView的话原理很简单,没啥理解的东西,直接贴代码了:

效果图:

                 

正文部分布局:

fragment_classify.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">
    <ListView
        android:id="@+id/teach_classify_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:listSelector="#00000000"/>
</LinearLayout>

classify_item.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="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/teach_classify_item_divider"
        android:background="#f3fdeeee"
        android:layout_width="match_parent"
        android:layout_height="10dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">


        <RelativeLayout
            android:id="@+id/teach_classify_left"
            android:layout_width="0dp"
            android:background="@drawable/item_pressed"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/teach_classify_item_iamge01"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_centerVertical="true"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:id="@+id/teach_classify_item_text01"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="60dp"
                android:gravity="center_vertical"
                android:text="@string/app_name" />

        </RelativeLayout>

        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#efe6e6" />

        <RelativeLayout
            android:id="@+id/teach_classify_right"
            android:layout_width="0dp"
            android:background="@drawable/item_pressed"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/teach_classify_item_iamge02"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_centerVertical="true"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:id="@+id/teach_classify_item_text02"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="60dp"
                android:gravity="center_vertical"
                android:text="@string/app_name" />

        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

头布局:

fragment_classify_header.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">
    <ImageView
        android:id="@+id/teach_classify_lv_header"
        android:src="@mipmap/ic_launcher"
        android:layout_width="match_parent"
        android:layout_height="180dp" />
</LinearLayout>

脚布局:

fragment_classify_bottom.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">
    <ImageView
        android:id="@+id/teach_classify_bottom"
        android:src="@mipmap/ic_launcher"
        android:layout_width="match_parent"
        android:layout_height="160dp" />
</LinearLayout> 

主页面:

public class ClassifyFragment extends BaseFragment implements ClassifyAdapter.OnClickItemListener{
    public static final String TAG = ClassifyFragment.class.getSimpleName();
    private ListView mListView;
    private ClassifyAdapter adapter;
    private ImageView mHeaderImage;
    private ImageView mBottomImage;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        layout = inflater.inflate(R.layout.fragment_classify, container, false);
        return layout;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        setupView();
    }
    /**
     * Header的添加最好放在setAdapter之前,在Android4.4之前,Header添加必须放在设置Adapter之前
     */
    private void initView() {
        mListView = ((ListView) layout.findViewById(R.id.teach_classify_listview));
        //header
        View headerView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_classify_header,null);
        mHeaderImage = ((ImageView) headerView.findViewById(R.id.teach_classify_lv_header));
        //可以添加多个HeaderView
        mListView.addHeaderView(hea



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • ListView添加头布局和脚布局,listview添加布局

相关文章

  • 2017-05-26Android实用工具类-GrallyAndPhotoUtils图片处理工具
  • 2017-05-26nginx rewrite常用示例
  • 2017-05-26Android 旋转屏幕--处理Activity与AsyncTask的最佳解决方案,androidasynctask
  • 2017-05-26android fragment生命周期应用
  • 2017-05-26Kotlin怎样使用Android的Dagger2,kotlindagger2
  • 2017-05-26Android笔记——Android自定义控件,android自定义控件
  • 2017-05-26Android-将RGB彩色图转换为灰度图,
  • 2018-01-28Android Studio 错误解决办法
  • 2017-05-26Android SwipeRefreshLayout下拉刷新与上拉加载+滑动删除
  • 2017-05-26Android Studio多渠道打包,androidstudio打包

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 三种POST和GET的提交方式,postget提交
    • 高仿人人网客户端Android版项目源码,高仿android
    • 仿QQ空间根据位置弹出PopupWindow显示更多操作效果,popupwindow
    • cobbler系统使用之二高级篇的补充篇---关于kickstart文件内容的配置说明
    • [android] 手机卫士手势滑动切换屏幕,android手势
    • Android Drawable的9种子类 介绍
    • Android Studio创建/打开项目时一直处于Building“project name”Gradle project info的解决办法,androidgradle
    • Android热补丁动态修复技术(二):实战!CLASS_ISPREVERIFIED问题!
    • android:Activity数据传递之静态变量
    • 360多渠道打包,360打包

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有