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); 
相關問題