我正在奇怪地实现我自己的日历,gridView没有完全出现。我数字正常,但屏幕不满。这是一半。我想实现类似于CalendarView的东西。
请检查您将理解的快照:
你能看到很多空的灰色空间吗?如何使它成为全屏?
以下是两个与日历
相关的xmlCalendarView.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/calendarMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/calendar_top" >
</RelativeLayout>
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:layout_gravity="center_horizontal"
android:listSelector="@android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />
</RelativeLayout>
接下来是CalendarItems.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/calendar_cell"
android:gravity="center"
android:orientation="vertical"
android:padding="2dip" >
<TextView
android:id="@+id/date"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="16dip" >
</TextView>
<TextView
android:id="@+id/textvaluedate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/date"
android:textColor="#F44336"
android:textSize="10dip"
android:visibility="gone" >
</TextView>
</LinearLayout>
尝试更改match_parent的所有内容仍然相同。我不确定我在哪里出错?
有人可以帮我解决这个问题吗?
谢谢!
更新2:
我已根据 @Heshan Sandeepa 更新了我的代码。我得到了全屏,但图像框看起来很大。请看一下屏幕截图。这可能有什么问题?
这是我的Baseadapter中的CODE:
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
int height = metrics.heightPixels;
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, month.get(Calendar.YEAR));
calendar.set(Calendar.MONTH, month.get(Calendar.MONTH));
int numDays = calendar.getActualMaximum(Calendar.DATE);
double rowCounts = Math.ceil(numDays/7);
int rowCount = (int) rowCounts;
if (convertView == null)
{
LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.calendar_item, null);
}
v.setMinimumHeight(height / rowCount);
}
我要求的是每个日期都需要更大的方框。就是这样。
让我知道!
谢谢!
答案 0 :(得分:0)
对于列,您可以通过strechMode read here达到上述要求。对于行,您可以通过以下步骤实现此目的,
计算设备高度。
getWindowManager().getDefaultDisplay().getMetrics(new DisplayMetrics());
int deviceHeight = new DisplayMetrics().heightPixels;
减少操作栏高度/任何填充(如果有的话)
您可以确定所需的行数,然后可以定义每行的高度(实际上是单元格)。您可以通过将相关月份的天数除以7来获得行号,并获得上限值。
前jan
int rowCount = Math.ceil(31/7);
= 5
ex - Feb(小心,这里不需要获取天花板,因为你可以得到整数)
int rowCount = Math.ceil(28/7);
= 4
所有月份相同。
现在您有屏幕高度(步骤2)和行数(步骤3),因此可以定义每个ro的确切高度。我希望你有一个适配器和每个单元格的自定义视图。 在getView()上为自定义视图充气时,请将计算出的高度定义为最小高度。
your_view.setMinimumHeight(<device height / rowCount>)