Контент CalenderView не отображается - PullRequest
0 голосов
/ 26 мая 2018

Поэтому я пытаюсь показать / скрыть просмотр календаря по нажатию кнопки. Но в итоге показываю только белый макет.

// xml

<android.support.constraint.ConstraintLayout
        android:id="@+id/header_view"
        android:elevation="@dimen/height4"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <CalendarView
            android:background="@color/white"
            android:visibility="invisible"
            app:layout_constraintTop_toBottomOf="@+id/date_view"
            android:id="@+id/calendarView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="true"
            android:paddingBottom="0dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="parent">

        </CalendarView>

        <android.support.constraint.ConstraintLayout
            android:background="@color/white"
            android:id="@+id/date_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

           //some other layouts
        </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

Я знаю, потому что я установил фон календаря на белый, но содержимое также должно отображаться.Проверьте выходное изображение enter image description here

Но когда я показываю просмотр календаря напрямую (устанавливая видимость видимым), он работает отлично, ТАК что в xml нет проблем.

Вот как я обрабатываю шоу / скрытие календаря

private void setUpCalenderView() {
        isCalenderVisible=!isCalenderVisible;
        if (isCalenderVisible){
            //((CalendarView) findViewById(R.id.calendarView)).setVisibility(View.VISIBLE);


            ((CalendarView) findViewById(R.id.calendarView)).setVisibility(View.VISIBLE);


        }
        else{

            ((CalendarView) findViewById(R.id.calendarView)).setVisibility(View.INVISIBLE);
        }
    }

Редактировать:

Это суть кода: https://gist.github.com/ankurtagtaste/692335e71ed0576b1e852292536d0ebf

Ответы [ 2 ]

0 голосов
/ 26 мая 2018

Я только что попробовал, это прекрасно работает:

<CalendarView
       android:layout_width="match_parent"
        android:layout_below="@+id/textView2"
        android:layout_height="match_parent"
        android:id="@+id/cal"
         />

Идея состоит в том, чтобы удалить android:visibility="invisible" из вашего макета и сделать это программно

         cal=x.findViewById(R.id.cal);
         cal.setVisibility(View.INVISIBLE);
 textView2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (cal.getVisibility()==View.VISIBLE)
                        cal.setVisibility(View.INVISIBLE);
                    else
                        cal.setVisibility(View.VISIBLE);
                }
            });
0 голосов
/ 26 мая 2018

Вам нужно будет изменить:

android:visibility="visible"

Чтобы сделать представление календаря видимым в формате xml

Вместо изменения видимости с представлением календаря вы можете использовать средство выбора даты

...