""https://i.sstatic.net/uQprG.png" alt="此处输入图像描述"/ >
Hi,
As you can see in above image, I created a custom view as as item of my calendar.
In code i have repeat it for example 50 times to create calendar.
服务器给我发送一个旗帜, 显示其中哪个应该选中( 在此情况下, 选择了 09 Jun ) 。
我的问题是当服务器发送一个不在屏幕上的一天( 例如 25 Jun) 时, 日期会被选中( 25 Jun 更改的背景), 但是在屏幕上我可以看到图像( 但现在 9 Jun 的背景已变换为白色 ) 。
我要找的就是在屏幕中间显示 6月25日的项目。我不知道它是如何可能的。
请提出任何建议。 Mu 习惯观点(widget)的代码是这样的:
public class Calendar_Item extends RelativeLayout {
private LayoutInflater mInflater;
private RelativeLayout rlContainer;
private TextView tvMonth;
private TextView tvDay;
private ImageView imDot;
public Calendar_Item(Context context) {
super(context);
init(context);
}
public Calendar_Item(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public Calendar_Item(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout calendarView = (RelativeLayout) mInflater.inflate(R.layout.calendar_item, null);
addView(calendarView);
rlContainer = (RelativeLayout) calendarView.findViewById(R.id.cal_rlContainer);
tvMonth = (TextView) calendarView.findViewById(R.id.cal_month);
tvDay = (TextView) calendarView.findViewById(R.id.cal_date);
imDot = (ImageView) calendarView.findViewById(R.id.cal_dot);
}
public void setMonth(String month) {
tvMonth.setText(month);
}
public void setMonth(int resId) {
tvMonth.setText(resId);
}
public CharSequence getMonth() {
return tvMonth.getText();
}
public void setDay(String day) {
tvDay.setText(day);
}
public void setDay(int resId) {
tvDay.setText(resId);
}
public CharSequence getDay() {
return tvDay.getText();
}
public void showDot() {
imDot.setVisibility(View.VISIBLE);
}
public void hideDot() {
imDot.setVisibility(View.INVISIBLE);
}
public void setTextColor(int color) {
tvDay.setTextColor(color);
}
public void setBackgroundResource(int resid) {
rlContainer.setBackgroundResource(resid);
}
public void setBackgroundDrawable(Drawable d) {
rlContainer.setBackgroundDrawable(d);
}
public void setBackgroundColor(int color) {
rlContainer.setBackgroundColor(color);
}
}
XML 代码布局 :
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_below = "@id/header"
android:fadingEdgeLength = "30dip"
android:fadingEdge = "horizontal"
android:scrollbars = "none" >
<LinearLayout
android:id = "@+id/llCalendarItems"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:orientation = "horizontal" >
</LinearLayout>
</HorizontalScrollView>
所有日历项目都位于LinearLayout内。