最近公司要求的上线项目有这么一个需求,要写一个请假申请的页面,里面必须有请假开始时间,结束时间,还有一个请假原因。

于是想到时间选择嘛,官方不是有个DatePicker吗?额,是不是要DatePicker哦,sorry,楼主有点英文犯愁,于是去看一看安卓原生态的时间选择器,感觉还行,基本的功能都有呈现,就将就着用呗。

没事去串了串负责开发IOS端的同事的UI,我去,这么高大上,简直就是高富帅和白富美用的嘛,再看看我的,什么玩意儿,丑的有模有样,真是有点儿意思。

如果让同样的功能,给我们安卓端一个这么丑的玩意儿,还真的是抹黑!!折煞了我们大安卓的开源性,于是,自己写呗,咦,似乎有个叫WheelView的玩意儿,额,就是这个,在它上面下点功夫。

额,还是先给大家带来个运行图,要是大家觉得有用,可以花个几分钟碎片时间瞧一瞧,不要钱的。看不了放心,看不了舒心!

代码中实现了弹出动画,以及一些shape的定义。

由于上面共享手机屏幕软件的原因,无法直接看到软键盘,而实际上在我们的真机上是可以直接弹出软键盘的,并且输入框的高度会随着软键盘上升且不会覆盖输入框上部布局,实际效果是这样~~

额,其实实现起来很简单很简单啦,对于要使用wheelView的代码,网上搜一大堆,你也可以去楼主上传代码的github网站下载Demo自行获取。

项目已同步至github:https://github.com/nanchen2251/DateTestDemo

对于实现上给大家稍微讲解一下。

首先是把必须用到的几个java代码拷贝进去,也就是我上传demo的Adapter和widget两个包。

主页面的布局相当简单,就4个按钮。

 <LinearLayout 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"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity"> <Button
android:id="@+id/tv_edit"
style="@style/btn_bg"
android:text="弹出可输入的对话框"/> <Button
android:id="@+id/tv_time"
style="@style/btn_bg"
android:layout_marginTop="10dp"
android:text="弹出时间"/> <Button
android:id="@+id/tv_date"
style="@style/btn_bg"
android:layout_marginTop="10dp"
android:text="弹出日期"/> <Button
android:id="@+id/tv_date_time"
style="@style/btn_bg"
android:layout_marginTop="10dp"
android:text="弹出日期时间"/> </LinearLayout>

主页面的代码MainActivity.java

在其中目前用到动画的是自定义的AlertDialog,其实代码中也实现了popWindow跳出的另一种方式,具体大家自行脑补。

具体的代码上就相对简单啦,我相信小伙伴们一看就能明了,不过大家在开发中真的需要仔细,楼主就在开发这个的时候写了一个TimeUtils,因为写错一个参数导致调了两小时,不过当然错误没在这个Demo中发生啦,是在楼主写的项目中。

很简单的代码逻辑,基本就是4个按钮,分别设置一个点击事件,跳转到一个自定义的AlertDialog,设置一些布局的基本用处,再通过初始化WheelView的值,额,因为在时间上每个月的天数有些不一致,在闰年平年也有不一致,所以需要写一个方法对此进行标注。额,好像没有了耶。

代码中也注释得很清楚啦。还是直接上代码吧。

 package com.example.nanchen.datetest;

 import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.TextView;
import android.widget.Toast; import com.example.nanchen.datetest.adapter.NumericWheelAdapter;
import com.example.nanchen.datetest.widget.WheelView; import java.util.Calendar;
import java.util.Locale; /**
* @author nanchen
* @date 2016-08-08
*/
public class MainActivity extends Activity{
private LayoutInflater inflater = null;
private WheelView year;
private WheelView month;
private WheelView day;
private WheelView hour;
private WheelView mins; PopupWindow menuWindow; Button tv_time,tv_date,popBtn;
private Button btn_edit; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
tv_time=(Button) findViewById(R.id.tv_time);//时间选择器
tv_date=(Button) findViewById(R.id.tv_date);//日期选择器 popBtn = (Button) findViewById(R.id.tv_date_time); btn_edit = (Button) findViewById(R.id.tv_edit);
btn_edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
showPopwindow(getEditText());
}
}); tv_time.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// showPopwindow(getTimePick());//弹出时间选择器
showTimeDialog();
}
});
tv_date.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// showPopwindow(getDataPick());//弹出日期选择器
showDateDialog();
}
}); popBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// showMyNewDate(getDateAndTime());
showDateAndTime();
}
});
} /**
* 初始化popupWindow
* @param view
*/
private void showPopwindow(View view) {
menuWindow = new PopupWindow(view,LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
menuWindow.setFocusable(true);
menuWindow.setBackgroundDrawable(new BitmapDrawable());
menuWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
menuWindow.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
menuWindow=null;
}
});
} private View getEditText() {
View view = inflater.inflate(R.layout.edit_layout,null);
final EditText editText = (EditText) view.findViewById(R.id.editText);
InputMethodManager manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
manager.toggleSoftInput(0,InputMethodManager.HIDE_IMPLICIT_ONLY);
Button btn_ok = (Button) view.findViewById(R.id.btn_ok);
Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
btn_ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,editText.getText().toString(),Toast.LENGTH_SHORT).show();
menuWindow.dismiss();
}
});
btn_cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
menuWindow.dismiss();
}
});
return view;
} /**
*
* @return
*/
private View getTimePick() {
View view = inflater.inflate(R.layout.time_picker_layout, null);
hour = (WheelView) view.findViewById(R.id.hour);
initHour();
mins = (WheelView) view.findViewById(R.id.mins);
initMins();
// 设置当前时间
hour.setCurrentItem(8);
mins.setCurrentItem(30); hour.setVisibleItems(7);
mins.setVisibleItems(7); Button bt = (Button) view.findViewById(R.id.set);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String str = hour.getCurrentItem() + ":"+ mins.getCurrentItem();
Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
menuWindow.dismiss();
}
});
Button cancel = (Button) view.findViewById(R.id.cancel);
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
menuWindow.dismiss();
}
}); return view;
} /**
*
* @return
*/
private View getDataPick() {
Calendar c = Calendar.getInstance();
int curYear = c.get(Calendar.YEAR);
int curMonth = c.get(Calendar.MONTH) + 1;//通过Calendar算出的月数要+1
int curDate = c.get(Calendar.DATE);
final View view = inflater.inflate(R.layout.datepicker_layout, null); year = (WheelView) view.findViewById(R.id.year);
initYear();
month = (WheelView) view.findViewById(R.id.month);
initMonth();
day = (WheelView) view.findViewById(R.id.day);
initDay(curYear,curMonth); year.setCurrentItem(curYear - 1950);
month.setCurrentItem(curMonth - 1);
day.setCurrentItem(curDate - 1);
year.setVisibleItems(7);
month.setVisibleItems(7);
day.setVisibleItems(7); Button bt = (Button) view.findViewById(R.id.set);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String str = (year.getCurrentItem()+1950) + "-"+ (month.getCurrentItem()+1)+"-"+(day.getCurrentItem());
Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
menuWindow.dismiss();
}
});
Button cancel = (Button) view.findViewById(R.id.cancel);
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
menuWindow.dismiss();
}
});
return view;
} /**
*
* @param year
* @param month
* @return
*/
private int getDay(int year, int month) {
int day = 30;
boolean flag = false;
switch (year % 4) {
case 0:
flag = true;
break;
default:
flag = false;
break;
}
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;
break;
case 2:
day = flag ? 29 : 28;
break;
default:
day = 30;
break;
}
return day;
}
/**
* 初始化年
*/
private void initYear() {
NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this,1950, 2050);
numericWheelAdapter.setLabel(" 年");
// numericWheelAdapter.setTextSize(15); 设置字体大小
year.setViewAdapter(numericWheelAdapter);
year.setCyclic(true);
} /**
* 初始化月
*/
private void initMonth() {
NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this,1, 12, "%02d");
numericWheelAdapter.setLabel(" 月");
// numericWheelAdapter.setTextSize(15); 设置字体大小
month.setViewAdapter(numericWheelAdapter);
month.setCyclic(true);
} /**
* 初始化天
*/
private void initDay(int arg1, int arg2) {
NumericWheelAdapter numericWheelAdapter=new NumericWheelAdapter(this,1, getDay(arg1, arg2), "%02d");
numericWheelAdapter.setLabel(" 日");
// numericWheelAdapter.setTextSize(15); 设置字体大小
day.setViewAdapter(numericWheelAdapter);
day.setCyclic(true);
} /**
* 初始化时
*/
private void initHour() {
NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this,0, 23, "%02d");
numericWheelAdapter.setLabel(" 时");
// numericWheelAdapter.setTextSize(15); 设置字体大小
hour.setViewAdapter(numericWheelAdapter);
hour.setCyclic(true);
} /**
* 初始化分
*/
private void initMins() {
NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this,0, 59, "%02d");
numericWheelAdapter.setLabel(" 分");
// numericWheelAdapter.setTextSize(15); 设置字体大小
mins.setViewAdapter(numericWheelAdapter);
mins.setCyclic(true);
} /**
* 显示全部日期
*/
private void showDateAndTime(){
Calendar c = Calendar.getInstance();
int curYear = c.get(Calendar.YEAR);
int curMonth = c.get(Calendar.MONTH) + 1;//通过Calendar算出的月数要+1
int curDate = c.get(Calendar.DATE);
int curHour = c.get(Calendar.HOUR_OF_DAY);
int curMin = c.get(Calendar.MINUTE); final AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
.create();
dialog.show();
Window window = dialog.getWindow();
// 设置布局
window.setContentView(R.layout.date_time_picker_layout);
// 设置宽高
window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
// 设置弹出的动画效果
window.setWindowAnimations(R.style.AnimBottom); year = (WheelView) window.findViewById(R.id.new_year);
initYear();
month = (WheelView) window.findViewById(R.id.new_month);
initMonth();
day = (WheelView) window.findViewById(R.id.new_day);
initDay(curYear,curMonth);
hour = (WheelView) window.findViewById(R.id.new_hour);
initHour();
mins = (WheelView) window.findViewById(R.id.new_mins);
initMins(); // 设置当前时间
year.setCurrentItem(curYear - 1950);
month.setCurrentItem(curMonth - 1);
day.setCurrentItem(curDate - 1);
hour.setCurrentItem(curHour);
mins.setCurrentItem(curMin); month.setVisibleItems(7);
day.setVisibleItems(7);
hour.setVisibleItems(7);
mins.setVisibleItems(7); // 设置监听
TextView ok = (TextView) window.findViewById(R.id.set);
TextView cancel = (TextView) window.findViewById(R.id.cancel);
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String time = String.format(Locale.CHINA,"%04d年%02d月%02d日 %02d时%02d分",year.getCurrentItem()+1950,
month.getCurrentItem()+1,day.getCurrentItem()+1,hour.getCurrentItem(),mins.getCurrentItem());
Toast.makeText(MainActivity.this, time, Toast.LENGTH_LONG).show();
dialog.cancel();
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
LinearLayout cancelLayout = (LinearLayout) window.findViewById(R.id.view_none);
cancelLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
dialog.cancel();
return false;
}
});
} /**
* 显示时间
*/
private void showTimeDialog(){
final AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
.create();
dialog.show();
Window window = dialog.getWindow();
// 设置布局
window.setContentView(R.layout.time_picker_layout);
// 设置宽高
window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
// 设置弹出的动画效果
window.setWindowAnimations(R.style.AnimBottom); Calendar c = Calendar.getInstance();
int curHour = c.get(Calendar.HOUR_OF_DAY);
int curMin = c.get(Calendar.MINUTE); hour = (WheelView) window.findViewById(R.id.hour);
initHour();
mins = (WheelView) window.findViewById(R.id.mins);
initMins();
// 设置当前时间
hour.setCurrentItem(curHour);
mins.setCurrentItem(curMin); hour.setVisibleItems(7);
mins.setVisibleItems(7); // 设置监听
Button ok = (Button) window.findViewById(R.id.set);
Button cancel = (Button) window.findViewById(R.id.cancel);
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String str = String.format(Locale.CHINA,"%2d:%2d",hour.getCurrentItem(), mins.getCurrentItem());
Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
dialog.cancel();
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
LinearLayout cancelLayout = (LinearLayout) window.findViewById(R.id.view_none);
cancelLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
dialog.cancel();
return false;
}
});
} /**
* 显示日期
*/
private void showDateDialog() {
final AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
.create();
dialog.show();
Window window = dialog.getWindow();
// 设置布局
window.setContentView(R.layout.datepicker_layout);
// 设置宽高
window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
// 设置弹出的动画效果
window.setWindowAnimations(R.style.AnimBottom); Calendar c = Calendar.getInstance();
int curYear = c.get(Calendar.YEAR);
int curMonth = c.get(Calendar.MONTH) + 1;//通过Calendar算出的月数要+1
int curDate = c.get(Calendar.DATE);
year = (WheelView) window.findViewById(R.id.year);
initYear();
month = (WheelView) window.findViewById(R.id.month);
initMonth();
day = (WheelView) window.findViewById(R.id.day);
initDay(curYear,curMonth); year.setCurrentItem(curYear - 1950);
month.setCurrentItem(curMonth - 1);
day.setCurrentItem(curDate - 1);
year.setVisibleItems(7);
month.setVisibleItems(7);
day.setVisibleItems(7); // 设置监听
Button ok = (Button) window.findViewById(R.id.set);
Button cancel = (Button) window.findViewById(R.id.cancel);
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String str = String.format(Locale.CHINA,"%4d年%2d月%2d日",year.getCurrentItem()+1950,month.getCurrentItem()+1,day.getCurrentItem()+1);
Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
dialog.cancel();
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
LinearLayout cancelLayout = (LinearLayout) window.findViewById(R.id.view_none);
cancelLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
dialog.cancel();
return false;
}
}); } }

另外的几个小布局也意义奉上。

date_time_picker_layout.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"> <LinearLayout
android:id="@+id/view_none"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"> <TextView
android:id="@+id/cancel"
android:layout_width="120dp"
android:layout_height="match_parent"
android:background="#fff"
android:gravity="center"
android:text="取消"
android:textColor="#1298FF"/> <TextView
android:id="@+id/set"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#fff"
android:gravity="center"
android:text="确定"
android:textColor="#1298FF"/>
</RelativeLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="horizontal"
android:paddingBottom="10dp"> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/new_year"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_weight="0.9"/> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/new_month"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_weight="1"/> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/new_day"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_weight="1"/> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/new_hour"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_weight="1"/> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/new_mins"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginRight="5dip"
android:layout_weight="1"/>
</LinearLayout> </LinearLayout> </LinearLayout>

datepicker_layout.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <LinearLayout
android:id="@+id/view_none"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
>
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center"
android:orientation="vertical"> <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#fff"
android:orientation="horizontal"> <Button
android:id="@+id/cancel"
android:layout_width="120dp"
android:layout_height="fill_parent"
android:background="@drawable/dialog_btn_right_selector"
android:text="取消"
android:textColor="#5C5D5C"/>
<Button
android:id="@+id/set"
android:layout_width="120dp"
android:layout_height="fill_parent"
android:background="@drawable/dialog_btn_left_selector"
android:text="确定"
android:layout_alignParentRight="true"
android:textColor="#1298FF"/>
</RelativeLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingBottom="20dp"
android:paddingTop="10dp"
android:orientation="horizontal"> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/year"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginLeft="5dip"
android:layout_marginTop="10dip"
android:layout_weight="0.8"/> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/month"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:layout_weight="1"/> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/day"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:layout_weight="1"/>
</LinearLayout> </LinearLayout> </LinearLayout>

time_picker_layout.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"> <LinearLayout
android:id="@+id/view_none"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#fff"
android:orientation="horizontal"> <Button
android:id="@+id/cancel"
android:layout_width="120dp"
android:layout_height="fill_parent"
android:background="@drawable/dialog_btn_right_selector"
android:text="取消"
android:textColor="#5C5D5C"/>
<Button
android:id="@+id/set"
android:layout_width="120dp"
android:layout_height="match_parent"
android:background="@drawable/dialog_btn_left_selector"
android:text="确定"
android:layout_alignParentRight="true"
android:textColor="#1298FF"/>
</RelativeLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingBottom="20dp"
android:paddingTop="10dp"
android:paddingRight="30dp"
android:paddingLeft="30dp"
android:orientation="horizontal"> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/hour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/> <com.example.nanchen.datetest.widget.WheelView
android:id="@+id/mins"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout> </LinearLayout> </LinearLayout>

edit_layout.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"> <LinearLayout
android:id="@+id/view_none"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#fff"
android:orientation="horizontal"> <Button
android:id="@+id/btn_cancel"
android:layout_width="120dp"
android:layout_height="fill_parent"
android:background="@drawable/dialog_btn_right_selector"
android:text="取消"
android:textColor="#5C5D5C"/>
<Button
android:id="@+id/btn_ok"
android:layout_width="120dp"
android:layout_height="match_parent"
android:background="@drawable/dialog_btn_left_selector"
android:text="确定"
android:layout_alignParentRight="true"
android:textColor="#1298FF"/>
</RelativeLayout> <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="请输入文本..."/>
</LinearLayout> </LinearLayout>

对于楼主自己画的.9图和一些drawable以及anim包里面的东西楼主就不一一奉上了,大家还是去github看吧~https://github.com/nanchen2251/DateTestDemo

额。对了,对于小伙伴们之前问的如何让键盘谈起不覆盖布局并且当输入文本框拉伸的时候对其他布局不造成影响的方式很简单,只需要在你的activity的申明中这样。

 <activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize">

是的,就加那么一句,完美实现。

另外需要让输入框获得焦点自动弹出软键盘的方式也很简单,两句话完美解决。

 InputMethodManager manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
manager.toggleSoftInput(0,InputMethodManager.HIDE_IMPLICIT_ONLY);

额,ok啦,楼主还堆着一大堆的项目代码等着去完成,但是楼主都尽量地抽出时间为大家分享楼主的真切感受,如果大家觉得有所帮助的话,别忘了分享点赞关注,把相对有用的东西分享给更多的人,对于不足之处,还请见谅,我不是大牛,我只是你们的同行者,欢迎指正~~

注:此文章为原创,欢迎转载,请在文章页面明显位置给出此文链接:http://www.cnblogs.com/liushilin/p/5749481.html
若您觉得这篇文章还不错请点击下右下角的推荐,非常感谢!

放弃安卓原生TimePicker,选择wheelView打造更漂亮的时间get,以及动态拉伸输入框布局,这些,这里都有!的更多相关文章

  1. 【安卓开发】用PageTransformer打造更好的动画效果

    Android的ViewPager类已经变成一个相当流行的Android应用组件了.它简单直观,并且提供了极好的功能.你可以经常在设置向导,图片画廊种看到它,它还是分开应用内容的良好方式. 标准的Vi ...

  2. MSYS2是对MSYS的一个独立的重写,是基于当前的Cygwin和MinGW-w64重写的,以同原生的Windows软件有更好的交互性为目的

    MSYS2的官网:http://sourceforge.net/projects/msys2/ 官网的描述: Description MSYS2 is an independent rewrite o ...

  3. AI剪辑和自定义UI,打造更智能的剪辑体验

    为满足开发者构建高效的应用内视频编辑能力,7月的HMS Core 6.0 推出了视频编辑服务(Video Editor Kit),一站式的视频处理能力获得了积极反响.同时,我们也关注到开发者需要集成丰 ...

  4. 【2021/12/31】uniapp之安卓原生插件开发教程

    uniapp之安卓原生插件开发教程 准备 hbuilderX,下载 app离线SDK,下载 Andorid Studio,安卓官方或中文社区 证书(可以自己准备,也可以使用android Studio ...

  5. 产品 | GreatSQL,打造更好的MGR生态

    欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 用 ...

  6. Unity实现相似于安卓原生项目的点击安卓返回button回到前一页的功能

    本章博主和大家一起讨论下Unity怎么实现类似安卓原生项目,点击安卓返回button实现返回到前一个页面的功能. 1.定义一个泛型用于响应安卓的返回button public static List& ...

  7. angularjs中安卓原生APP调用H5页面js函数,js写法应注意

    安卓原生app调用js方法,js方法应写在html下的script标签内,不能有任何function包裹,例如angular的controller层,这样APP也是获取不到的: 所以只有放在html中 ...

  8. Qt 打开安卓相冊选择图片并获取图片的本地路径

    Qt 打开安卓相冊选择图片并获取图片的本地路径 过程例如以下: 通过 Intent 打开安卓的系统相冊. 推荐使用 QAndroidJniObject::getStaticObjectField 获取 ...

  9. 将H5页面打包成安卓原生app

    第一步:下载HBuilderX,新建项目选择5+App新建一个空项目如下图 新建后项目目录结构如下图 第二步,将你要打包成安卓app的文件打包,最后生成的文件目录如下图 1.打包完成后,将对应文件内容 ...

随机推荐

  1. MySQL高级知识- MySQL的架构介绍

    [TOC] 1.MySQL 简介 概述 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司. MySQL是一种关联数据库管理系统,将数据保存在不同的表中,而 ...

  2. 隐私泄露杀手锏 —— Flash 权限反射

    [简版:http://weibo.com/p/1001603881940380956046] 前言 一直以为该风险早已被重视,但最近无意中发现,仍有不少网站存在该缺陷,其中不乏一些常用的邮箱.社交网站 ...

  3. 【SQLServer】【恢复挂起的解决方案】附加文件时候的提示“无法重新生成日志,原因是数据库关闭时存在打开的事务/用户,该数据库没有检查点或者该数据库是只读的。 ”【数据库恢复】

    汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 先贴错误: 吐槽一下: 进入正题: 新建一个同名数据库 停止MSSQL服务 替换数据库文 ...

  4. HTML5 介绍

    本篇主要介绍HTML5规范的内容和页面上的架构变动. 目录 1. HTML5介绍 1.1 介绍 1.2 内容 1.3 浏览器支持情况 2. 创建HTML5页面 2.1 <!DOCTYPE> ...

  5. PHP-会员登录与注册例子解析-学习笔记

    1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...

  6. ASP.NET Core中如影随形的”依赖注入”[上]: 从两个不同的ServiceProvider说起

    我们一致在说 ASP.NET Core广泛地使用到了依赖注入,通过前面两个系列的介绍,相信读者朋友已经体会到了这一点.由于前面两章已经涵盖了依赖注入在管道构建过程中以及管道在处理请求过程的应用,但是内 ...

  7. 【HanLP】资料链接汇总

    Java中调用HanLP配置 HanLP自然语言处理包开源官方文档 了解HanLP的全部 自然语言处理HanLP 开源自由的汉语言处理包主页 GitHub源码 基于hanLP的中文分词详解-MapRe ...

  8. C++随笔:.NET CoreCLR之GC探索(2)

    首先谢谢 @dudu 和 @张善友 这2位大神能订阅我,本来在写这个系列以前,我一直对写一些核心而且底层的知识持怀疑态度,我为什么持怀疑态度呢?因为一般写高层语言的人99%都不会碰底层,其实说句实话, ...

  9. FFmpeg 中AVPacket的使用

    AVPacket保存的是解码前的数据,也就是压缩后的数据.该结构本身不直接包含数据,其有一个指向数据域的指针,FFmpeg中很多的数据结构都使用这种方法来管理数据. AVPacket的使用通常离不开下 ...

  10. MyBatis源码分析(二)语句处理器

    StatementHandler 语句处理器,主要负责语句的创建.参数的设置.语句的执行.不负责结果集的处理. Statement prepare(Connection connection, Int ...