CalendarView高度包装当前月份

时间:2016-07-20 16:39:49

标签: java android calendarview

问题就是这么说,我在我的布局中使用CalendarView进行简单的月视图,用户可以选择日期,但由于某种原因,CalendarView只占用整个屏幕,有没有办法制作CalendarView一次只显示一个月而不是占用整个屏幕?谢谢

xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

<CalendarView
    android:id="@+id/calendar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</CalendarView>

</LinearLayout>

java:

public class CalendarActivity extends AppCompatActivity {

     CalendarView calendarview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendar_layout);

        calendarview = (CalendarView) findViewById(R.id.calendar);

}
}

3 个答案:

答案 0 :(得分:1)

虽然不是很简单。我确实使用了calenderview,我在github上使用这个库做了它

https://github.com/SundeepK/CompactCalendarView

尝试使用它,它非常灵活和可扩展!

答案 1 :(得分:0)

如果用户只选择日期,则可以使用DatePickerFragment。从棒棒糖开始只有一个月了。

创建DatePickerFragment

public static class DatePickerFragment extends DialogFragment
                        implements DatePickerDialog.OnDateSetListener {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    // Create a new instance of DatePickerDialog and return it
    return new DatePickerDialog(getActivity(), this, year, month, day);
}

public void onDateSet(DatePicker view, int year, int month, int day) {
    // Do something with the date chosen by the user
    }
}

显示Fragmet

DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");

希望获得此帮助,有关Pickers here

的更多信息

答案 2 :(得分:0)

将其放入ScrollView

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <CalendarView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/calendarView" />
</ScrollView>

对我有用。