Android CalendarView高度不匹配_parent

时间:2017-12-15 06:20:54

标签: android android-layout calendar android-calendar

我想像以下代码一样使用CalendarView全屏。

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

但此视图高度在设备上显示为wrap_content

enter image description here

github中是否有全屏CalendarView?我找不到 - 或者我可以真正地提出这个观点match_parent

任何建议将不胜感激。

2 个答案:

答案 0 :(得分:0)

https://github.com/dengshiwei/CalendarComponent

在MonthView中

@override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if(widthMode == MeasureSpec.AT_MOST){
widthSize = (int) (300 * density);
}
if(heightMode == MeasureSpec.AT_MOST){
heightSize = (int) density * 200;
}
if(widthMode == MeasureSpec.AT_MOST){
widthSize = (int) density * 300;
}
width = widthSize;
NUM_ROWS = 10; 

setMeasuredDimension(widthSize, heightSize);
}

上面这段代码使calendarview height match_parent。谢谢你的帮助。

答案 1 :(得分:-1)

试试这种方式。希望这会有所帮助。

日历将如下所示。 enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <CalendarView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical">
    </CalendarView>

</FrameLayout>

</LinearLayout>