public void onDraw(Canvas canvas)
{
//获得当前View的宽度
int width = getWidth();
int offset = width / 8;
int currentPosition = offset;
//设置要绘制的字体
mPaint.setTypeface(Typeface.create(Typeface.DEFAULT_BOLD, Typeface.BOLD));
mPaint.setTextSize(30);
mPaint.setColor(Color.rgb(0, 134, 139));
for(int i = 0; i < 7 ; i++)
{
//圈出当前的日期
if( day == i)
{
System.out.println("画出当前的日期!");
}
canvas.drawText(days[i], currentPosition, 30, mPaint);
currentPosition += offset;
}
//调用父类的绘图方法
super.onDraw(canvas);
}
<?xml version="1.0" encoding="utf-8"?> <!--模仿课程表的界面--> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!--显示时间--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white"> <TextView android:id="@+id/year" android:layout_width="wrap_content" android:layout_height="50dp" android:layout_gravity="center" android:gravity="center" android:layout_marginLeft="20dp" android:textSize="20dp" android:text="2016年"/> <!--竖线--> <View android:layout_width="1dp" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:background="#00FFFF" /> <!--下拉方式选周数--> <Spinner android:id="@+id/switchWeek" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:layout_gravity="center" /> </LinearLayout> <!--分隔线--> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#00FF7F"/> <!--显示星期--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:background="@android:color/white"> <cn.karent.demo.UI.WeekTitle android:layout_width="match_parent" android:layout_height="30dp" android:layout_marginTop="10dp"/> </LinearLayout> <!--显示课表详细信息--> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!--显示多少节课--> <LinearLayout android:layout_width="25dp" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:text="一" android:textSize="10dp" android:gravity="center"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="二" android:gravity="center"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="三" android:gravity="center"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="四" android:gravity="center"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="五" android:gravity="center"/> <TextView android:layout_width="wrap_content" android:layout_height="92dp" android:textSize="12dp" android:text="六" android:gravity="center"/> </LinearLayout> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="#E5E5E5"/> <GridView android:id="@+id/courceDetail" android:layout_width="match_parent" android:layout_height="match_parent" android:numColumns="7" android:horizontalSpacing="1dp" android:verticalSpacing="1dp" android:stretchMode="columnWidth" android:background="#E5E5E5"> </GridView> </LinearLayout> </ScrollView> </LinearLayout>
public class MyAdapter extends BaseAdapter {
private Context mContext;
//保存内容的内部数组
private List<String> content;
public MyAdapter(Context context, List<String> list) {
this.mContext = context;
this.content = list;
}
public int getCount() {
return content.size();
}
public Object getItem(int position) {
return content.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
if( convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.grib_item, null);
}
TextView textView = (TextView)convertView.findViewById(R.id.text);
//如果有课,那么添加数据
if( !getItem(position).equals("")) {
textView.setText((String)getItem(position));
textView.setTextColor(Color.WHITE);
//变换颜色
int rand = position % 7;
switch( rand ) {
case 0:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.grid_item_bg));
break;
case 1:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_12));
break;
case 2:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_13));
break;
case 3:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_14));
break;
case 4:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_15));
break;
case 5:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_16));
break;
case 6:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_17));
break;
case 7:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_18));
break;
}
}
return convertView;
}
}
convertView=LayoutInflater.from(mContext).inflate(R.layout.grib_item, null);
if( !getItem(position).equals("")) {
textView.setText((String)getItem(position));
textView.setTextColor(Color.WHITE);
//变换颜色
int rand = position % 7;
switch( rand ) {
case 0:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.grid_item_bg));
break;
case 1:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_12));
break;
case 2:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_13));
break;
case 3:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_14));
break;
case 4:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_15));
break;
case 5:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_16));
break;
case 6:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_17));
break;
case 7:
textView.setBackground(mContext.getResources().getDrawable(R.drawable.bg_18));
break;
}
}
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#75B7A0" /> <corners android:radius="3dip" /> </shape>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F4FFF5EE"> <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="80dp" android:layout_marginLeft="3dp" android:layout_marginRight="3dp" android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:padding="2dp" android:textSize="12dp" android:gravity="center"/> </RelativeLayout>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有