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

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

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

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

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

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

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

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

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

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

额,其实实现起来很简单很简单啦,对于要使用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
若您觉得这篇文章还不错请点击下右下角的推荐,非常感谢!

上一篇:聊一聊HTML 标签


下一篇:HTML 标签