然而,我对你的问题进行了深思熟虑,发现你的布局设计没有什么问题,你必须通过确定看法的班子来开展各种活动,从而避免任何其它事件的重叠。
http://postimg.org/image/4lqmlnhk7/ (Output for Reference)
private int[] Gettimespan(int SHour, int EHour, int SMinutes, int EMinutes, int TotalWidth) {
// float x = (60 / Minutes) * 100;
int x = 0; // width for time marking
int y = 0; // Height For hour marking
int z = 0; // Margin left for Stime
int YAxis = 0; // YAxis Adjustment
int TotalYAxis = 80; // /Total YAxis of Per hour slot
int HalfOf_TotalYAxis = 40; // /Half of the Total YAxis of Per hour slot
int MinutesDiff = GetMinutes(SHour, EHour, SMinutes, EMinutes);
int xAxisFinetuning = 0;
//Check If any Views Between
final RelativeLayout rl = (RelativeLayout) _activity.findViewById(R.id.relativeLayout4);
List<Integer> ViewCount = DetectView(SHour, rl);
if(ViewCount.size() > 1 && ViewCount != null)
{
for(int i = 0; i < ViewCount.size(); i++)
{
LinearLayout ll = (LinearLayout) _activity.findViewById(ViewCount.get(i));
int Stepper = TotalWidth / ViewCount.size();
xAxisFinetuning += Stepper;
z = xAxisFinetuning;
ll.setMinimumWidth(Stepper - 15);
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) ll.getLayoutParams();
p.leftMargin = z;
ll.requestLayout();
x = Stepper - 26;
//Log.d("LayoutID", "" + ll.getId());
}
}
//Snippet 1: Case Same hour but upper span
//if(SMinutes >= 0 && EMinutes >= 30 && SMinutes <= 30 && ((SHour+1 == EHour) || (SHour == EHour)))
if(SMinutes >= 0 && EMinutes >= 30 && SMinutes <= 30 && (SHour == EHour))
{
if(x == 0)
{
x = TotalWidth;
}
if(y == 0)
{
if(MinutesDiff > 30)
{
y = dpToPx(TotalYAxis);
}
else
{
y = dpToPx(HalfOf_TotalYAxis);
}
}
//if(z == 0)
//{
z = 0;
//}
if(MinutesDiff >= 30)
{
YAxis = 0;
}
else
{
YAxis = HalfOf_TotalYAxis;
}
return new int[] { x, y - 6, z, YAxis };
}
// End Snippet 1.
//Snippet 2: Case Same hour but lower span
//if(SMinutes >= 30 && ((SHour+1 == EHour) || (SHour == EHour)))
if(SMinutes >= 30 && (SHour == EHour))
{
if(x == 0)
{
x = TotalWidth;
}
if(y == 0)
{
if(MinutesDiff > 30)
{
y = dpToPx(TotalYAxis);
}
else
{
y = dpToPx(HalfOf_TotalYAxis);
}
}
z = 0;
if(MinutesDiff > 30)
{
YAxis = 0;
}
else
{
YAxis = HalfOf_TotalYAxis;
}
return new int[] { x, y - 6, z, YAxis };
}
// End Snippet 2.
//Snippet 3: Case when Total Hour > 1
if(SHour != EHour )
{
if(x == 0)
{
x = TotalWidth;
}
if(y == 0)
{
Log.d("Calendar Case Next Day", "Ehour " + EHour + " Shour " + SHour);
if((EHour - SHour)<=1)
{
y = dpToPx(((EHour - SHour)+1) * TotalYAxis);
}
else
{
y = dpToPx(((EHour - SHour)) * TotalYAxis);
}
}
z = 0;
YAxis = 0;
return new int[] { x, y - 6, z, YAxis };
}
// End Snippet 3.
return new int[] { x, y - 6, z, YAxis };
}
private void TimeSpanning(LinearLayout LL, int SHour, int EHour, int SMinutes, int EMinutes, int TotalWidth, TextView Tv) {
if(SHour > EHour)
{
Log.d("Calendar Case Next Day_", "Ehour " + EHour + " Shour " + SHour + " TextView " + Tv.getText());
EHour = 24;
//EMinutes = 59;
}
int minuteAdjustment = 0;
if((EHour + ":" + EMinutes).equalsIgnoreCase(SHour + ":" + SMinutes))
{
//Log.d("EqualFound","True");
minuteAdjustment = 59;
}
int[] x = Gettimespan(SHour, EHour, SMinutes, EMinutes + minuteAdjustment, TotalWidth);
//Log.d("Eminute"," - " + EMinutes);
LL.setMinimumWidth(x[0]);
LL.setMinimumHeight(x[1]);
Tv.setWidth(x[0]);
Tv.setHeight(x[1] - 14);
int Padding_Top_Bottom = 4;
int Padding_Left_Right = 4;
//LL.setPadding(30, 30, 30, 30);
//tv.setWidth(x[0]);
//tv.setHeight(x[1]);
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) LL.getLayoutParams();
//ViewGroup.MarginLayoutParams p1 = (ViewGroup.MarginLayoutParams) ll.getLayoutParams();
switch (SHour) {
case 0: {
// 12 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(0) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 1: {
// 1 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(1) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 2: {
// 2 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(2) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 3: {
// 3 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(3) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 4: {
// 4 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(4) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 5: {
// 5 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(5) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 6: {
// 6 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(6) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 7: {
// 7 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(7) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 8: {
// 8 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(8) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 9: {
// 9 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(9) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 10: {
// 10 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(10) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 11: {
// 11 am
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(11) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 12: {
// 12 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(12) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 13: {
// 1 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(13) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 14: {
// 2 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(14) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 15: {
// 3 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(15) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 16: {
// 4 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(16) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 17: {
// 5 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(17) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 18: {
// 6 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(18) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 19: {
// 7 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(19) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 20: {
// 8 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(20) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 21: {
// 9 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(21) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 22: {
// 10 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(22) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
case 23: {
// 11 pm
p.setMargins(x[2] + Padding_Left_Right, dpToPx(GetCalendarScaleY(23) + x[3]) + Padding_Top_Bottom, Padding_Left_Right, 0);
LL.requestLayout();
break;
}
}
}
private int dpToPx(int dp) {
if(_activity != null)
{
DisplayMetrics displayMetrics = _activity.getResources().getDisplayMetrics();
int px = 0;
if(displayMetrics != null)
{
px = Math.round((float) dp * ((float)displayMetrics.densityDpi / (float)DisplayMetrics.DENSITY_DEFAULT));
return px;
}
}
return 0;
}
private int GetCalendarScaleY(int Time) {
//Coordinates of Rows (Y Axis with respect to hours)
int x = 0;
switch (Time) {
case 0: {
// 12 am
x = 0;
break;
}
case 1: {
// 1 am
x = 80;
break;
}
case 2: {
// 2 am
x = 160;
break;
}
case 3: {
// 3 am
x = 240;
break;
}
case 4: {
// 4 am
x = 320;
break;
}
case 5: {
// 5 am
x = 400;
break;
}
case 6: {
// 6 am
x = 480;
break;
}
case 7: {
// 7 am
x = 560;
break;
}
case 8: {
// 8 am
x = 640;
break;
}
case 9: {
// 9 am
x = 720;
break;
}
case 10: {
// 10 am
x = 800;
break;
}
case 11: {
// 11 am
x = 880;
break;
}
case 12: {
// 12 pm
x = 960;
break;
}
case 13: {
// 1 pm
x = 1040;
break;
}
case 14: {
// 2 pm
x = 1120;
break;
}
case 15: {
// 3 pm
x = 1200;
break;
}
case 16: {
// 4 pm
x = 1280;
break;
}
case 17: {
// 5 pm
x = 1360;
break;
}
case 18: {
// 6 pm
x = 1440;
break;
}
case 19: {
// 7 pm
x = 1520;
break;
}
case 20: {
// 8 pm
x = 1600;
break;
}
case 21: {
// 9 pm
x = 1680;
break;
}
case 22: {
// 10 pm
x = 1760;
break;
}
case 23: {
// 11 pm
x = 1840;
break;
}
}
return x;
}