Android SwipeSelector
Android SwipeSelector
Android SwipeSelector是github上一个第三方开源的项目,其项目主页:https://github.com/roughike/SwipeSelector
SwipeSelector实现一种选择方式,类似于ViewPager,如动图所示:
SwipeSelector本身的例子比较清晰,容易看懂,使用SwipeSelector,先写一个布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="披萨饼"
android:textAppearance="@style/TextAppearance.AppCompat.Title" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="选项"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="#DDDDDD" /> <com.roughike.swipeselector.SwipeSelector
android:id="@+id/sizeSelector"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="#DDDDDD" /> <com.roughike.swipeselector.SwipeSelector
android:id="@+id/toppingSelector"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="#DDDDDD" /> <com.roughike.swipeselector.SwipeSelector
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/deliverySelector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:swipe_descriptionGravity="center"
app:swipe_descriptionTextAppearance="@style/TextAppearance.AppCompat.Body1"
app:swipe_indicatorActiveColor="@android:color/holo_red_light"
app:swipe_indicatorInActiveColor="@android:color/holo_blue_light"
app:swipe_indicatorMargin="20dp"
app:swipe_indicatorSize="10dp"
app:swipe_titleTextAppearance="@style/TextAppearance.AppCompat.Title" /> <View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="#DDDDDD" /> <Button
android:id="@+id/sendButton"
style="?attr/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="@android:color/holo_orange_dark"
android:text="提交"
android:textColor="#FFFFFF" />
</LinearLayout>
</ScrollView>
注意最后一个SwipeSelector的变化,重新定制了一些样式。
上层Java代码:
package zhangphil.demo; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast; import com.roughike.swipeselector.SwipeItem;
import com.roughike.swipeselector.SwipeSelector; public class MainActivity extends AppCompatActivity {
/**
* Size options
*/
private static final int SIZE_KIDS = 0;
private static final int SIZE_NORMAL = 1;
private static final int SIZE_LARGE = 2;
private static final int SIZE_HUGE = 3; /**
* Topping options
*/
private static final int TOPPINGS_EMILY = 0;
private static final int TOPPINGS_BOB = 1;
private static final int TOPPINGS_HANS = 2;
private static final int TOPPINGS_ANDREI = 3; /**
* 邮递选项
*/
private static final int DELIVERY_NONE = 0;
private static final int DELIVERY_YES = 1; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final SwipeSelector sizeSelector = (SwipeSelector) findViewById(R.id.sizeSelector);
sizeSelector.setItems(
new SwipeItem(-1, "请选择尺寸", "Start by swiping left."),
new SwipeItem(SIZE_KIDS, "Kids' size", "For the small appetite. Can be shared by four toddlers."),
new SwipeItem(SIZE_NORMAL, "Normal", "Our most popular size. Ideal for kids before their growth spurt."),
new SwipeItem(SIZE_LARGE, "Large", "This is two times the normal size. Suits well for the hangover " +
"after a bachelor party."),
new SwipeItem(SIZE_HUGE, "Huge", "Suitable for families. Also perfect for a bigger appetite if your " +
"name happens to be Furious Pete.")
); final SwipeSelector toppingSelector = (SwipeSelector) findViewById(R.id.toppingSelector);
toppingSelector.setItems(
new SwipeItem(-1, "Select toppings", "Start by swiping left."),
new SwipeItem(TOPPINGS_EMILY, "Aunt Emily's", "Strawberries, potatoes and cucumber. Just what Aunt " +
"Emily found in her backyard."),
new SwipeItem(TOPPINGS_BOB, "Uncle Bob's Special", "Ranch dressing, bacon, kebab and double pepperoni. " +
"And also some lettuce, because lettuce is healthy."),
new SwipeItem(TOPPINGS_HANS, "Hans' Meat Monster", "Ham, sauerbraten, salami and bratwurst. Hans likes " +
"his meat."),
new SwipeItem(TOPPINGS_ANDREI, "Andreis' Russian Style", "Whole pickles and sour cream. Prijat" +
"novo appetita!")
); final SwipeSelector deliverySelector = (SwipeSelector) findViewById(R.id.deliverySelector);
deliverySelector.setItems(
new SwipeItem(-1, "选择邮递选项", "Start by swiping left."),
new SwipeItem(DELIVERY_NONE, "No delivery", "Come to our lovely restaurant and pick up the pizza yourself."),
new SwipeItem(DELIVERY_YES, "Delivery", "Our minimum-wage delivery boy will bring you the pizza by his own " +
"scooter using his own gas money.")
); findViewById(R.id.sendButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SwipeItem selectedSize = sizeSelector.getSelectedItem();
SwipeItem selectedToppings = toppingSelector.getSelectedItem();
SwipeItem selectedDelivery = deliverySelector.getSelectedItem(); String toastMessage = ""; if ((Integer) selectedSize.value != -1) {
toastMessage += "Size: " + selectedSize.title;
} else {
toastMessage += "No size selected.";
} if ((Integer) selectedToppings.value != -1) {
toastMessage += "\nToppings: " + selectedToppings.title;
} else {
toastMessage += "\nNo toppings selected.";
} if ((Integer) selectedDelivery.value != -1) {
toastMessage += "\nDelivery: " + selectedDelivery.title;
} else {
toastMessage += "\nNo delivery method selected.";
} Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_LONG).show();
}
});
}
}
代码运行结果:
Android SwipeSelector的更多相关文章
- 59.Android开源项目及库 (转)
转载 : https://github.com/Tim9Liu9/TimLiu-Android?hmsr=toutiao.io&utm_medium=toutiao.io&utm_so ...
- Android开源项目及库搜集
TimLiu-Android 自己总结的Android开源项目及库. github排名 https://github.com/trending,github搜索:https://github.com/ ...
- 各种Android UI开源框架 开源库
各种Android UI开源框架 开源库 转 https://blog.csdn.net/zhangdi_gdk2016/article/details/84643668 自己总结的Android开源 ...
- 2019年最新android常用开源库汇总上篇(转)
1.基本控件 1.1.TextView ScrollNumber ReadMoreTextView HtmlImage android-autofittextview html-textview Ba ...
- 【原】Android热更新开源项目Tinker源码解析系列之三:so热更新
本系列将从以下三个方面对Tinker进行源码解析: Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Android热更新开源项目Tinker源码解析系列之二:资源文件热更新 A ...
- 配置android sdk 环境
1:下载adnroid sdk安装包 官方下载地址无法打开,没有vpn,使用下面这个地址下载,地址:http://www.android-studio.org/
- Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记
以前写下拉刷新 感觉好费劲,要判断ListView是否滚到顶部,还要加载头布局,还要控制 头布局的状态,等等一大堆.感觉麻烦死了.今天学习了SwipeRefreshLayout 的用法,来分享一下,有 ...
- Android Studio配置 AndroidAnnotations——Hi_博客 Android App 开发笔记
以前用Eclicps 用习惯了现在 想学学 用Android Studio 两天的钻研终于 在我电脑上装了一个Android Studio 并完成了AndroidAnnotations 的配置. An ...
- Android请求网络共通类——Hi_博客 Android App 开发笔记
今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...
随机推荐
- HTTP/0.9、HTTP/1.0、HTTP/1.1、HTTP/2 历史演变和设计思路(详)*
HTTP 协议是互联网的基础协议,也是网页开发的必备知识,最新版本 HTTP/2 更是让它成为技术热点. 本文介绍 HTTP 协议的历史演变和设计思路. 一.HTTP/0.9 HTTP 是基于 TCP ...
- 关于minSdkVersion="8" 升级appcompat_v7包主题"Theme.AppCompat.Light"等不存在的问题
关于minSdkVersion="8" 升级后,又不想用 appcompat_v7包, 那么appcompat_v7主题"Theme.AppCompat.Light&qu ...
- Nuget 自定义配置(官网)
<?xml version="1.0" encoding="utf-8"?> <configuration> <config> ...
- 转】Nodejs对MongoDB模糊查询
原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/4/ 感谢! Posted: Jul 1, 2013 Tag ...
- HashMap和List遍历方法总结及如何遍历删除元素
https://blog.csdn.net/demohui/article/details/77748809
- 学习笔记 第九章 使用CSS美化表格
第9章 使用CSS美化表格 学习重点 正确使用表格标签: 设置表格和单元格属性: 设计表格的CSS样式. 9.1 表格的基本结构 表格由行.列.单元格3部分组成,单元格时行与列交叉的部分. 在HTM ...
- 461在全志r16平台tinav3.0系统下使用地磁计QMC5883L
461在全志r16平台tinav3.0系统下使用地磁计QMC5883L 2018/9/7 14:08 版本:V1.0 开发板:SC3817R SDK:tina v3.0 (基本确认全志tina v3. ...
- 未找到框架“.NETFramework,Version=v4.5”的引用程序集
问题描述 一般是在编译的时候会出现这样子的问题, 问题原因: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETF ...
- 从0开始搭建SQL Server 2012 AlwaysOn 第二篇(配置故障转移集群)
本篇主要讲配置Windows 故障转移集群及遇到的相关问题(坑),因为AlwaysOn是基于Windows的故障转移集群的 在讲解步骤之前需要了解一下故障转移集群仲裁配置 四种集群的仲裁配置: 1.多 ...
- mongodb用户权限管理(二)
数据库 分配用户权限 有了创建语法,和参数说明,接下来开始实践. 注意,还有一点,账号是跟着数据库绑定的,在那个库里授权,就在那个库里验证(auth) 否则会失败 创建 账号管理授权权限 的账号 &g ...