SwipRefreshLayout下拉刷新控件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/swip_refresh_layout"> <ListView
android:id="@+id/my_list_view_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</android.support.v4.widget.SwipeRefreshLayout>

swip_refresh_layout_index.xml

package com.ouc.wkp.ui1;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast; import java.util.ArrayList;
import java.util.List; /**
* Created by wkp on 2016/8/25.
*/
public class SwipRefreshLayoutDemo extends Activity { SwipeRefreshLayout swipeRefreshLayout;
ListView listView; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.swip_refresh_layout_index); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swip_refresh_layout);
listView = (ListView) findViewById(R.id.my_list_view_refresh); final List<String> dataList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
dataList.add(i + "");
} final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, dataList);
listView.setAdapter(adapter)
;
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//true点击后变成刷新状态
swipeRefreshLayout.setRefreshing(false);
Toast.makeText(SwipRefreshLayoutDemo.this, "加载完成", Toast.LENGTH_SHORT).show(); for (int i = 0; i < 20; i++) {
dataList.add("新加的数据" + i);
}
adapter.notifyDataSetChanged();
}
}, 2000);
}
}); swipeRefreshLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.GRAY);
swipeRefreshLayout.setProgressViewOffset(false,200,300);
}
}

SwipRefreshLayout.java

DrawerLayout侧滑控制菜单

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <!--第一个子View会作为内容显示区-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="你所需要显示的内容" />
</LinearLayout> <!--第二个子View会作为侧滑菜单-->
<!--android:layout_gravity="start" end left right-->
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@android:color/white"> <ListView
android:id="@+id/list_view"
android:layout_width="150dp"
android:layout_height="match_parent">
</ListView>
</LinearLayout> <LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@android:color/white"
android:orientation="vertical"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="退出登录"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

drawer_layout_index.xml

package com.ouc.wkp.ui1;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView; import java.util.List; /**
* Created by wkp on 2016/8/25.
*/
public class DrawerLayoutDemo extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_layout_index); ListView listView = (ListView) findViewById(R.id.list_view);
ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, new String[]{"菜单1", "菜单2", "菜单3", "菜单4", "菜单5"});
listView.setAdapter(adapter);
}
}

DrawerLayoutDemo.java

RecyclerView循环复用控件

首先在这个文件最下面添加一行,注意版本和倒数第二行对应。

这个控件有点复杂

<?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"> <android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

recycler_view_index.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="100dp"
android:layout_height="60dp"> <TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

item_view_recyclerview.xml

package com.ouc.wkp.ui1;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView; /**
* Created by wkp on 2016/8/26.
*/
public class RecyclerViewDemo extends Activity { RecyclerView recyclerView;
String[] dataArr = {"第0项", "第1项", "第2项",
"第0项", "第1项", "第2项",
"第0项", "第1项", "第2项",
"第0项", "第1项", "第2项",
"第0项", "第1项", "第2项",
}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recycler_view_index); recyclerView = (RecyclerView) findViewById(R.id.recycler_view); //true进行反转
LinearLayoutManager layoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
//layoutManager
recyclerView.setLayoutManager(new GridLayoutManager(this,3)); MyAdapter adapter = new MyAdapter();
recyclerView.setAdapter(adapter);
} private class MyAdapter extends RecyclerView.Adapter { @Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { //parent表示继承父类 false不能少
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view_recyclerview, parent, false);
MyViewHolder viewHolder = new MyViewHolder(itemView); return viewHolder;
} @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((MyViewHolder) holder).textView.setText("编号:" + position);
} @Override
public int getItemCount() {
return dataArr.length;
} private class MyViewHolder extends RecyclerView.ViewHolder { private TextView textView; public MyViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.text_view);
}
}
}
}

RecyclerViewDemo.java

Android入门——UI(9)的更多相关文章

  1. Android入门——UI(8)——Fragment(2)

    先演示一下如何在一个activity中放置两个Fragment,先定义两个Fragment <?xml version="1.0" encoding="utf-8& ...

  2. Android入门——UI(7)——Fragment

    先上fragment静态加载的代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...

  3. android入门——UI(6)——ViewPager+Menu+PopupWindow

    一.使用ViewPager开发新特性引导界面 <?xml version="1.0" encoding="utf-8"?> <Relative ...

  4. android入门——UI(5)

    最近时间实在匆忙,博客的代码基本没有解释. 介绍ExpandableListView <?xml version="1.0" encoding="utf-8&quo ...

  5. android入门——UI(4)

    GridView控件实现菜单 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xml ...

  6. android入门——UI(3)

    Spinner控件   ListView控件 一.Spinner控件 点击Spinner会弹出一个包含所有可选值的dropdown菜单,从该菜单中可以为Spinner选择一个新值. 有两种指定数据源的 ...

  7. Android入门——UI(2)

    介绍SeekBar拖动条控件.ProgressBar进度条控件.DatePicker日历控件.TimePicker时间控件 <?xml version="1.0" encod ...

  8. android入门——UI(1)

    一.使用TextView ImageView Button EditView做出登录页面 <?xml version="1.0" encoding="utf-8&q ...

  9. 【详细】Android入门到放弃篇-YES OR NO-》各种UI组件,布局管理器,单元Activity

    问:达叔,你放弃了吗? 答:不,放弃是不可能的,丢了Android,你会心疼吗?如果别人把你丢掉,你是痛苦呢?还是痛苦呢?~ 引导语 有人说,爱上一个人是痛苦的,有人说,喜欢一个人是幸福的. 人与人之 ...

随机推荐

  1. MongoDB C driver API continues

    开篇前 <1,mongoc_init() func> mongoc_init() Synopsis void mongoc_init (void); Description This fu ...

  2. Linux多线程编程小结

     Linux多线程编程小结 前一段时间由于开题的事情一直耽搁了我搞Linux的进度,搞的我之前学的东西都遗忘了,非常烦躁的说,如今抽个时间把之前所学的做个小节.文章内容主要总结于<Linux程序 ...

  3. Swift类与结构、存储属性、计算属性、函数与方法、附属脚本等

    写了12个Person来复习,不过完成同样的代码需要敲键盘的次数相比OC确实少了很多,这很多应该归功于Swift中不写分号,以及少了OC中的中括号. 一.类与结构体 两者在Swift中差不了多少了 类 ...

  4. 安装Linux系统到u盘

    第一步:首先插入u盘到电脑主机usb接口处(建议插入到主机箱后置的usb接口).然后打开UltraISO软件,再打开选择须要写入u盘的Ubuntu 10.04或者其它版本号的Linux系统的iso镜像 ...

  5. SQL Server DML(SELECT)常见用法(二)

    1   引言 上篇讲到SQL Server中DML的基本使用方法,其中SELECT语句是最常用的语句,其功能强大,结构复杂,下面通过例子,具体介绍其使用方法. 2 SELECT查询语句 SELECT语 ...

  6. z-index解决弹出层遮罩层覆盖子div不能显示输出的问题

    // 添加以下代码来进行测试: // ajax 发生错误,就会执行$('body').ajaxError(function(e, xhr, setting, text){    // e - even ...

  7. Android自定义工具类获取按钮并绑定事件(利用暴力反射和注解)

    Android中为按钮绑定事件的有几种常见方式,你可以在布局文件中为按钮设置id,然后在MainActivity中通过findViewById方法获取按钮对象实例,再通过setOnClickListe ...

  8. 二、fragment使用

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/8881711 我们都知道,Android上的界面展示都是通过Activity实现的, ...

  9. zoj1183 Scheduling Lectures

    这道题题意不想说了,跑了640ms,感觉水过去了,应该能通过单调队列优化,很长时间没碰已经不知道怎么写了,就说说现在的写法吧. 状态定义很关键:dp[i][j]把前j个topic放在前i堂课. 因为这 ...

  10. 使用 VB.NET 开发多线程

    摘要:.NET 框架提供了新的类,可以方便地创建多线程应用程序.本文介绍如何使用 Visual Basic® .NET 的多线程编程技术来开发效率更高.响应速度更快的应用程序. 目录 简介 多线程处理 ...