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 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...
随机推荐
- Python快速教程(转载)
Python快速教程 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 怎么能快速地掌握Python?这是和朋友闲聊时谈起的问题 ...
- 208 Implement Trie (Prefix Tree) 字典树(前缀树)
实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个方法.注意:你可以假设所有的输入都是小写字母 a-z.详见:https://leetcode.co ...
- SSH---整合Struts2&Spring&Hibernate(实例)
一.SSH回顾 Struts2:核心为过滤器+拦截器.过程:Filter--->FilterDispatcher-->ActionMapper-->ActionProxy--> ...
- npm安装淘宝镜像cnpm报错npm ERR! errno -4048
今天在安装淘宝镜像的时候报错了,第一次遇上,表示很懵逼 然后捣腾了半天以为是npm install 的时候出错,后来网上查到是 装淘宝镜像cnpm的时候报错,好像是权限问题,解决方法: npm ca ...
- linux下redis安装访问
下载编译安装 wget http://download.redis.io/releases/redis-3.0.1.tar.gz tar xvf redis-3.0.1.tar.gz mv redis ...
- windows上把git生成的ssh key
右键鼠标,选中 “Git Bash here”: 输入指令,创建ssh key: cd ~/.ssh/ #bash: cd: /c/Users/Administrator/.ssh/: No such ...
- SQL Server中行列转置方法
PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P ...
- 初学者SQL shell(psql)无法登陆问题
因为项目第一次接触postgresql,有个问题搞死我了,如果初学,估计大家也会遇见这样的问题,希望可以节约时间. 用户postgres的口令不显示啊!服!
- 【4412开发板使用经验分享】迅为4412开发板I2C驱动问题
本文转自迅为论坛:bbs.topeetboard.com 我想写DS3231 的驱动 但是读回的数据老是-6 硬件: 我I2C设备连接的这几个GPIO,看了2.5的手册,接口应该是链接正确的 软件 分 ...
- jQuery 返回顶部效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...