Skip to content

Commit

Permalink
修改高度获取机制
Browse files Browse the repository at this point in the history
  • Loading branch information
骆大峰 committed Jun 28, 2017
1 parent 51fd83d commit cf6f703
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion calendar/src/main/java/com/ldf/calendar/view/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void onDraw(Canvas canvas) {
@Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
super.onSizeChanged(w, h, oldW, oldH);
cellHeight = w / Const.TOTAL_ROW;
cellHeight = h / Const.TOTAL_ROW;
cellWidth = w / Const.TOTAL_COL;
calendarAttr.setCellHeight(cellHeight);
calendarAttr.setCellWidth(cellWidth);
Expand Down
9 changes: 3 additions & 6 deletions calendar/src/main/java/com/ldf/calendar/view/MonthPager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class MonthPager extends ViewPager {
private int currentPosition = CURRENT_DAY_INDEX;
private int cellHeight = 0;
private int rowIndex = 6;
private int mCellSpace;

private ViewPager.OnPageChangeListener viewPageChangeListener;
private OnPageChangeListener monthPageChangeListener;
Expand Down Expand Up @@ -81,13 +80,13 @@ public void addOnPageChangeListener(OnPageChangeListener listener) {

@Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
mCellSpace = h / 6;
cellHeight = h / 6;
super.onSizeChanged(w, h, oldW, oldH);
}

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if(mCellSpace > 0){
super.onMeasure(widthMeasureSpec,MeasureSpec.makeMeasureSpec(mCellSpace * 6,
if(cellHeight > 0){
super.onMeasure(widthMeasureSpec,MeasureSpec.makeMeasureSpec(cellHeight * 6,
MeasureSpec.EXACTLY));
} else {
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
Expand All @@ -113,8 +112,6 @@ public int getTopMovableDistance() {
}

public int getCellHeight() {
CalendarViewAdapter calendarViewAdapter = (CalendarViewAdapter) getAdapter();
cellHeight = calendarViewAdapter.getPagers().get(currentPosition % 3).getCellHeight();
return cellHeight;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public CustomDayView(Context context, int layoutResource) {
dateTv = (TextView) findViewById(R.id.date);
marker = (ImageView) findViewById(R.id.maker);
selectedBackground = findViewById(R.id.selected_background);
selectedBackground = findViewById(R.id.selected_background);
todayBackground = findViewById(R.id.today_background);
}

Expand Down
2 changes: 1 addition & 1 deletion example/src/main/res/layout/activity_syllabus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<com.ldf.calendar.view.MonthPager
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_height="300dp"
android:background="#fff">
</com.ldf.calendar.view.MonthPager>

Expand Down
2 changes: 1 addition & 1 deletion example/src/main/res/layout/custom_day.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="51.4dp"
android:layout_height="60dp">
android:layout_height="50dp">
<View
android:id="@+id/today_background"
android:layout_width="33dp"
Expand Down

0 comments on commit cf6f703

Please sign in to comment.