我正在创建一个 DATEPICKER ,它是一个水平滚轮(自定义)。我正在使用此LIBRARY。我想要显示如下....
|Thu |
| |
|06 |
| |
|Aug |
但我会变得如下......
Thu 06 Aug
我试过下面的代码.....
MainActivity.java
package com.DatePicker.demodatepicker;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import antistatic.spinnerwheel.AbstractWheel;
import antistatic.spinnerwheel.adapters.ArrayWheelAdapter;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final AbstractWheel hours = (AbstractWheel) findViewById(R.id.hour_horizontal);
Calendar c = Calendar.getInstance();
String[] days = new String[30];
String[] dates = new String[30];
String[] months = new String[30];
String[] FinalArray = new String[30];
for (int i = 0; i <= 29; i++) {
Calendar BetweenDates = Calendar.getInstance();
BetweenDates.setTime(c.getTime());
BetweenDates.add(Calendar.DATE, i);
SimpleDateFormat dateFormate = new SimpleDateFormat(
"EEE, dd-MMM-yyyy");
String EachDate = dateFormate.format(BetweenDates.getTime());
String[] partsOne = EachDate.split(",");
days[i] = partsOne[0].trim();
String[] partTwo = partsOne[1].trim().split("-");
dates[i] = partTwo[0].trim();
months[i] = partTwo[1].trim();
String finalValue = days[i] + "\n" + dates[i] + "\n" + months[i];
FinalArray[i] = finalValue;
Log.e("Final String: ", finalValue);
}
ArrayWheelAdapter<String> adapter = new ArrayWheelAdapter<String>(this,
FinalArray);
adapter.setItemResource(R.layout.wheel_text_centered);
adapter.setItemTextResource(R.id.text);
hours.setViewAdapter(adapter);
}
}
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.DatePicker.demodatepicker.MainActivity" >
<antistatic.spinnerwheel.WheelHorizontalView
android:id="@+id/hour_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:selectionDivider="@drawable/divider_dark_gradient_horizontal"
app:selectionDividerWidth="1px"
app:visibleItems="3" />
</RelativeLayout>
wheel_text_centered.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#777777"
android:gravity="center"
android:lines="1"
android:textColor="#FFFFFF"
android:textSize="15dp"
android:textStyle="bold" />
</FrameLayout>
很抱歉没有上传截图,因为我无法上传。它是保密的。提前谢谢。
答案 0 :(得分:0)
将以下行添加到wheel_text_centered.xml文件中的TextView。
android:lines="3"
android:maxLines="4"
android:singleLine="false"
虽然很难,但这很简单。