Android自定義wheelview實(shí)現(xiàn)滾動(dòng)日期選擇器
本文實(shí)例為大家分享了Android實(shí)現(xiàn)滾動(dòng)日期選擇器的具體代碼,供大家參考,具體內(nèi)容如下
wheelview滾動(dòng)效果的View
這段時(shí)間需要用到一個(gè)時(shí)間選擇器,但是不能使用日期對(duì)話框,
因?yàn)樗呛Y選條件框架下的,只能是View!這個(gè)WheelView改造后可以達(dá)到要求!
這個(gè)wheelview框架使用的類不多,就幾個(gè),還有一些資源文件。
我根據(jù)這個(gè)框架設(shè)計(jì)了日期的選擇器。
主頁(yè)面:

第一種日期選擇器頁(yè)面:

動(dòng)態(tài)效果:

使用:
具體的實(shí)現(xiàn)是一個(gè)LoopView的類,這是一個(gè)繼承View的類!
理解LoopView的公開方法就可以了。
1.布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
>
<com.example.wheelview.loopview.LoopView
android:layout_marginTop="50dp"
android:id="@+id/loopView"
android:layout_width="match_parent"
android:layout_height="150dp"
app:awv_textsize="18"
/>
</LinearLayout>
2.控制代碼
package com.example.wheelview.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.example.wheelview.R;
import com.example.wheelview.loopview.LoopView;
import com.example.wheelview.loopview.OnItemSelectedListener;
import java.util.ArrayList;
public class MyActivity extends Activity {
private Toast toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LoopView loopView = (LoopView) findViewById(R.id.loopView);
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < 15; i++) {
list.add("item " + i);
}
//設(shè)置是否循環(huán)播放
// loopView.setNotLoop();
//滾動(dòng)監(jiān)聽
loopView.setListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(int index) {
if (toast == null) {
toast = Toast.makeText(MyActivity.this, "item " + index, Toast.LENGTH_SHORT);
}
toast.setText("item " + index);
toast.show();
}
});
//設(shè)置原始數(shù)據(jù)
loopView.setItems(list);
}
}
那個(gè)日期選擇器就是使用三個(gè)LoopView結(jié)合而成的!
LoopView類里面控制字體顏色和橫線顏色的地方:
//中間選中的字體顏色: 灰色:0xff313131,橙色:0xffec6f1a centerTextColor = typedArray.getInteger(R.styleable.androidWheelView_awv_centerTextColor, 0xffec6f1a); //沒(méi)被選中的字體的顏色 outerTextColor = typedArray.getInteger(R.styleable.androidWheelView_awv_outerTextColor, 0xffafafaf); //中間字體上下兩條橫線的顏色 dividerColor = typedArray.getInteger(R.styleable.androidWheelView_awv_dividerTextColor, 0xffc5c5c5);
其他的控制可以參考我的代碼
我的項(xiàng)目的代碼:wheelview滾動(dòng)效果的View
我的代碼中有一個(gè)時(shí)間的工具類,可以很方便的取到任何時(shí)間,你也可以在日期選擇器中多加一個(gè)按鈕,設(shè)置到今天的日期。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android使用Retrofit2.0技術(shù)仿微信發(fā)說(shuō)說(shuō)
這篇文章主要為大家詳細(xì)介紹了Android使用Retrofit2.0技術(shù)仿微信發(fā)說(shuō)說(shuō),實(shí)現(xiàn)拍照,選圖庫(kù),多圖案上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
Android實(shí)現(xiàn)Flip翻轉(zhuǎn)動(dòng)畫效果
這篇文章主要介紹了Android實(shí)現(xiàn)Flip翻轉(zhuǎn)動(dòng)畫效果,對(duì)Android程序設(shè)計(jì)人員有很好的參考借鑒價(jià)值,需要的朋友可以參考下2014-08-08
Android 日常開發(fā)總結(jié)的60條技術(shù)經(jīng)驗(yàn)
這篇文章主要介紹了Android日常開發(fā)總結(jié)的技術(shù)經(jīng)驗(yàn)60條,需要的朋友可以參考下2016-03-03
Android自定義ViewGroup嵌套與交互實(shí)現(xiàn)幕布全屏滾動(dòng)
這篇文章主要為大家介紹了Android自定義ViewGroup嵌套與交互實(shí)現(xiàn)幕布全屏滾動(dòng)效果示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
Flutter應(yīng)用框架運(yùn)行微信小程序方法
這篇文章主要介紹了在Flutter?App內(nèi)運(yùn)行微信小程序的過(guò)程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-02-02

