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. 【HDU 5532 Almost Sorted Array】水题,模拟

    给出一个序列(长度>=2),问去掉一个元素后是否能成为单调不降序列或单调不增序列. 对任一序列,先假设其可改造为单调不降序列,若成立则输出YES,不成立再假设其可改造为单调不增序列,若成立则输出 ...

  2. UML_行为图

    活动图是UML用于对系统的动态行为建模的另一种常用工具,它描述活动的顺序,展现从一个活动到另一个活动的控制流.活动图在本质上是一种流程图.活动图着重表现从一个活动到另一个活动的控制流,是内部处理驱动的 ...

  3. poj 1276 Cash Machine_多重背包

    题意:略 多重背包 #include <iostream> #include<cstring> #include<cstdio> using namespace s ...

  4. hdu 2222 Keywords_ac自动机模板

    题意:给你n个单词,再给你一串字符,求在字符中有多少个单词出现过 #include <iostream> #include<cstdio> #include<cstrin ...

  5. OpenStack开启sshd

    修改配置sshd的文件 1.      修改sshd配置文件 /etc/ssh/sshd_config 2.      将#PasswordAuthentication no的注释去掉,并将no改为y ...

  6. ngrok首页、文档和下载 - Web服务安全通道 - 开源中国社区

    ngrok首页.文档和下载 - Web服务安全通道 - 开源中国社区      Web服务安全通道 ngrok 编辑/纠错    分享到     新浪微博腾讯微博    已用    +0    收藏 ...

  7. 十个JAVA程序员容易犯的错误

    十个JAVA程序员容易犯的错误 1. Array 转 ArrayList 一般开发者喜欢用: List<String> list = Arrays.asList(arr); Arrays. ...

  8. linux中grep使用方法具体解释

    查找特定字符串并颜色显示 [root@fwq test]# grep -n 'the' regular_express.txt --color=auto 8:I can't finish the te ...

  9. js 检验密码强度

    html 代码如下: <!DOCTYPE HTML> <html lang="en"> <head> <meta charset=&quo ...

  10. 求S=a+aa+aaa+aaaa+aa...a的值

    问题描述:求S=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字,由输入a(1 <= a <= 9)表示,相加的元素个数由输入b(b<= 1000)表示. 这个算法的优 ...