0

我的活动中有一个RecyclerView,它显示了4种不同类型的卡。其中一张卡片显示来自此库WeekView的日历自定义视图。一切都显示好,直到我开始滚动我的视图,并且日历卡开始走出屏幕边界。定制全周来看,似乎可以得出在工具栏层导致图像单元格中的Android自定义视图

​​

After scroll

所示正如你可以看到cardview正在滚动正确的,但定制周视图将会上述效果在工具栏层上方。

在我Adapter我初始化我ViewHolder

calendarView = (WeekView) itemView.findViewById(R.id.todayView); 
if (calendarView != null) { 
      initializeCalendarView(calendarView); 
     } 


private void initializeCalendarView(WeekView mWeekView) { 
    mWeekView.setOnEventClickListener(this); 
    mWeekView.setMonthChangeListener(this); 
    mWeekView.setEventLongPressListener(this); 
    mWeekView.setEmptyViewLongPressListener(this); 
    setupDateTimeInterpreter(false, mWeekView); 
    mWeekView.goToToday(); 

    mWeekView.setColumnGap((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, context.getResources().getDisplayMetrics())); 
    mWeekView.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, context.getResources().getDisplayMetrics())); 
    mWeekView.setEventTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, context.getResources().getDisplayMetrics())); 
} 

WeekView这是我xmlCardView

<android.support.v7.widget.CardView 
    android:id="@+id/doctorDashboardCalendar" 
    android:layout_width="match_parent" 
    android:layout_height="800dp" 
    android:layout_margin="@dimen/margin10" 
    app:cardCornerRadius="3dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_gravity="center_vertical" 
      android:gravity="center_vertical" 
      android:background="#e0e0e0"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/notes_icon_dark" 
       android:layout_margin="10dp"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="@dimen/text18" 
       android:fontFamily="@string/font_name_2" 
       android:text="Calendar"/> 

     </LinearLayout> 

     <*************************.WeekView 
      android:id="@+id/todayView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:clipToPadding="true" 
      app:eventTextColor="@android:color/white" 
      app:textSize="12sp" 
      app:hourHeight="30dp" 
      app:headerColumnPadding="4dp" 
      app:headerColumnTextColor="@color/toolbar_text" 
      app:headerRowPadding="6dp" 
      app:columnGap="4dp" 
      app:noOfVisibleDays="1" 
      app:headerRowBackgroundColor="@color/toolbar" 
      app:dayBackgroundColor="#05000000" 
      app:todayBackgroundColor="@color/white" 
      app:headerColumnBackground="#ffffffff" 
      app:todayHeaderTextColor="@color/accent" 
      app:showNowLine="true" 
      app:nowLineColor="@color/colorAccent" 
      app:enableScrolling="false"/> 

    </LinearLayout> 

</android.support.v7.widget.CardView> 
+0

以任何机会你关闭剪辑的孩子吗?这是我通常看到类似的东西的唯一途径。 –

回答

0

添加到您的自定义视图:

android:margin_top="?attr/actionBarSize" 

Ť他将在操作栏/工具栏的大小上创建一个页边距,使滚动的大小固定。

0

我找到了解决方案。如果您在WeekView评论上述格式的代码,它的工作原理正确

canvas.clipRect(left, top, width, heigh, Region.Op.REPLACE); 
相关问题