簡體   English   中英

CalendarView高度以包裝當前月份

[英]CalendarView height to wrap current month

問題很好地說明了一切,我在布局中使用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);

}
}

這不是很簡單。 我確實使用了calenderview,我在github上使用了這個庫

https://github.com/SundeepK/CompactCalendarView

嘗試使用它,它非常靈活且可擴展!

如果用戶僅選擇日期,則可以使用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");

希望對您有所幫助,請點擊此處獲取更多信息。

將其放在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>

這對我行得通。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM