Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“Xamarin Android”;ScrollView";奇怪的行为_Android_Xamarin_Textview_Scrollview - Fatal编程技术网

“Xamarin Android”;ScrollView";奇怪的行为

“Xamarin Android”;ScrollView";奇怪的行为,android,xamarin,textview,scrollview,Android,Xamarin,Textview,Scrollview,我创建了自定义的“TextView”,在canvas.DrawText方法覆盖的OnDraw方法中绘制文本线。在添加ScrollView之前,一切都很好: <LinearLayout android:background="#ffffff" android:layout_height="200dp" android:layout_width="match_parent" android:orientation="horizontal"> <S

我创建了自定义的“TextView”,在canvas.DrawText方法覆盖的OnDraw方法中绘制文本线。在添加ScrollView之前,一切都很好:

<LinearLayout
    android:background="#ffffff"
    android:layout_height="200dp"
    android:layout_width="match_parent"
    android:orientation="horizontal">
  <ScrollView
    android:id="@+id/scrollV"
    android:layout_height="match_parent"
        android:layout_width="match_parent">
    <myapp.TextViewJustifiable
        android:id="@+id/textViewJustifiableAlertMessage"
        android:layout_gravity="top"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:lineSpacingExtra="8dp"
        android:textSize="16sp"
        android:textColor="#333333" />
  </ScrollView>
</LinearLayout>

通常,ScrollView不显示自定义TextView的第n个文本行!例如,如果TextView有20行文本,则只会滚动19行,而不显示20行!当我删除OnDraw方法时,一切都正常


您认为问题出在哪里?

我在重写OnDraw方法的末尾使用了SetHeight方法来解决问题:

> protected override void OnDraw(Canvas canvas)
>         {
>             float floatCharSpaceSize;
>             float floatWordWidth;
>             float floatEmptySpace;
>             float floatJustifedSpaceSize;
>             float floatLineWidth;
>             float floatTextAreaWidth;
>             float floatWordPositionX;
>             float floatWordPositionY;
>             int intLineEnd;
>             int intLineStart;
>             int intSpaceCount;
>             int intTextHeight;
>             int intRemaindedSpaceSize;
>             Layout layoutTextView;
>             Paint.FontMetrics fontMetrics_Paint;
>             string stringLine;
>             string stringText;
>             string[] stringArrWord;
>             TextPaint textPaint = Paint;
> 
>             textPaint.Color = new Color(CurrentTextColor);
>             textPaint.DrawableState = GetDrawableState();
>             floatTextAreaWidth = MeasuredWidth - (PaddingLeft + PaddingRight);
>             floatCharSpaceSize = textPaint.MeasureText(" ");
>             stringText = Text;
>             floatWordPositionY = TextSize + PaddingTop;
>             layoutTextView = Layout;
> 
>             if (layoutTextView == null)
>             {
>                 return;
>             }
> 
>             fontMetrics_Paint = textPaint.GetFontMetrics();
>             intTextHeight = (int)(Math.Ceiling(fontMetrics_Paint.Bottom - fontMetrics_Paint.Top) *
> LineSpacingMultiplier + layoutTextView.SpacingAdd);
> 
>             for (int intIndexA = 0; intIndexA < layoutTextView.LineCount; intIndexA++)
>             {
>                 intLineStart = layoutTextView.GetLineStart(intIndexA);
>                 intLineEnd = layoutTextView.GetLineEnd(intIndexA);
>                 floatLineWidth = StaticLayout.GetDesiredWidth(Text, intLineStart, intLineEnd, textPaint);
>                 stringLine = Text.Substring(intLineStart, intLineEnd - intLineStart);
> 
>                 if (stringLine[stringLine.Length - 1] == ' ')
>                 {
>                     stringLine = stringLine.Substring(0, stringLine.Length - 1);
>                     floatLineWidth -= floatCharSpaceSize;
>                 }
> 
>                 if (BoolJustify == true && intIndexA < layoutTextView.LineCount - 1)
>                 {
>                     floatEmptySpace = floatTextAreaWidth - floatLineWidth;
>                     intSpaceCount = stringLine.Split(' ').Length - 1;
>                     floatJustifedSpaceSize = (int)(floatEmptySpace / intSpaceCount) + floatCharSpaceSize;
>                     intRemaindedSpaceSize = (int)(((floatEmptySpace / intSpaceCount) - (int)(floatEmptySpace / intSpaceCount)) *
> intSpaceCount);
>                     stringArrWord = stringLine.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
> 
>                     if (IntLangDirection == (int)ApplicationLSchool.LangDirection.LTR)
>                     {
>                         floatWordPositionX = 0;
> 
>                         for (int intIndexB = 0; intIndexB < stringArrWord.Length; intIndexB++)
>                         {
>                             floatWordWidth = StaticLayout.GetDesiredWidth(stringArrWord[intIndexB], textPaint);
> 
>                             canvas.DrawText(stringArrWord[intIndexB], floatWordPositionX, floatWordPositionY, textPaint);
> 
>                             if (intRemaindedSpaceSize > 0)
>                             {
>                                 floatWordPositionX += floatWordWidth + floatJustifedSpaceSize + 1;
> 
>                                 intRemaindedSpaceSize--;
>                             }
>                             else
>                             {
>                                 floatWordPositionX += floatWordWidth + floatJustifedSpaceSize;
>                             }
>                         }
>                     }
>                     else if (IntLangDirection == (int)ApplicationLSchool.LangDirection.RTL)
>                     {
>                         floatWordPositionX = floatTextAreaWidth;
> 
>                         for (int intIndexB = 0; intIndexB < stringArrWord.Length; intIndexB++)
>                         {
>                             floatWordWidth = StaticLayout.GetDesiredWidth(stringArrWord[intIndexB], textPaint);
> 
>                             canvas.DrawText(stringArrWord[intIndexB], floatWordPositionX - floatWordWidth, floatWordPositionY, textPaint);
> 
>                             if (intRemaindedSpaceSize > 0)
>                             {
>                                 floatWordPositionX -= floatWordWidth + floatJustifedSpaceSize + 1;
> 
>                                 intRemaindedSpaceSize--;
>                             }
>                             else
>                             {
>                                 floatWordPositionX -= floatWordWidth + floatJustifedSpaceSize;
>                             }
>                         }
>                     }
>                 }
>                 else
>                 {
>                     if (IntLangDirection == (int)ApplicationLSchool.LangDirection.LTR)
>                     {
>                         canvas.DrawText(stringLine, 0, floatWordPositionY, textPaint);
>                     }
>                     else if (IntLangDirection == (int)ApplicationLSchool.LangDirection.RTL)
>                     {
>                         canvas.DrawText(stringLine, floatTextAreaWidth - floatLineWidth, floatWordPositionY, textPaint);
>                     }
>                 }
> 
>                 floatWordPositionY += intTextHeight;
>             }
> 
>             **SetHeight((int)(floatWordPositionY - TextSize - layoutTextView.SpacingAdd) + PaddingBottom);**
>         }
>受保护的覆盖void OnDraw(画布)
>         {
>浮动空间大小;
>浮动字宽度;
>漂浮空间;
>float-floatJustifedSpaceSize;
>浮动线宽;
>浮动区域宽度;
>浮点数x;
>浮动定位;
>int INTLINEND;
>int intLineStart;
>int空间计数;
>int intTextHeight;
>int intRemaindedSpaceSize;
>布局视图;
>Paint.FontMetrics FontMetrics_Paint;
>弦线;
>字符串文本;
>字符串[]stringArrWord;
>text油漆text油漆=油漆;
> 
>textPaint.Color=新颜色(CurrentTextColor);
>textPaint.DrawableState=GetDrawableState();
>floatTextAreaWidth=测量宽度-(左填充+右填充);
>floatCharSpaceSize=textPaint.MeasureText(“”);
>stringText=文本;
>floatWordPositionY=TextSize+PaddingTop;
>layoutTextView=布局;
> 
>if(layoutTextView==null)
>             {
>返回;
>             }
> 
>fontMetrics_Paint=textPaint.GetFontMetrics();
>intTextHeight=(int)(数学天花板(fontMetrics_Paint.Bottom-fontMetrics_Paint.Top)*
>LineSpacingMultiplier+layoutTextView.SpacingAdd);
> 
>对于(int intIndexA=0;intIndexA             {
>intLineStart=layoutTextView.GetLineStart(intIndexA);
>intLineEnd=layoutTextView.GetLineEnd(intIndexA);
>floatLineWidth=StaticLayout.GetDesiredWidth(文本、intLineStart、intLineEnd、textPaint);
>stringLine=Text.Substring(intLineStart,intLineEnd-intLineStart);
> 
>if(stringLine[stringLine.Length-1]='')
>                 {
>stringLine=stringLine.Substring(0,stringLine.Length-1);
>floatLineWidth-=floatCharSpaceSize;
>                 }
> 
>if(BoolJustify==true&&intIndexA                 {
>floatmptyspace=floattextraeawidth-floatLineWidth;
>intSpaceCount=stringLine.Split(“”).Length-1;
>floatJustifedSpaceSize=(int)(floatmptyspace/intSpaceCount)+floatCharSpaceSize;
>intRemaindedSpaceSize=(int)((floatEmptySpace/intSpaceCount)-(int)(floatEmptySpace/intSpaceCount))*
>intSpaceCount);
>stringArrWord=stringLine.Split(新字符[1]{''},StringSplitOptions.RemoveEmptyEntries);
> 
>if(IntLangDirection==(int)applicationschool.LangDirection.LTR)
>                     {
>floatWordPositionX=0;
> 
>对于(int intIndexB=0;intIndexB                         {
>floatWordWidth=StaticLayout.GetDesiredWidth(stringArrWord[intIndexB],textPaint);
> 
>DrawText(stringArrWord[intIndexB]、floatWordPositionX、floatWordPositionY、textPaint);
> 
>如果(IntremeIndedSpaceSize>0)
>                             {
>floatWordPositionX+=floatWordWidth+floatJustifedSpaceSize+1;
> 
>IntremeIndedSpaceSize--;
>                             }
>否则
>                             {
>floatWordPositionX+=floatWordWidth+floatJustifedSpaceSize;
>                             }
>                         }
>                     }
>else if(IntLangDirection==(int)applicationschool.LangDirection.RTL)
>                     {
>floatWordPositionX=floatTextAreaWidth;
> 
>对于(int intIndexB=0;intIndexB                         {
>floatWordWidth=StaticLayout.GetDesiredWidth(stringArrWord[intIndexB],textPaint);
> 
>DrawText(stringArrWord[intIndexB],floatWordPositionX-floatWordWidth,floatWordPositionY,textPaint);
> 
>如果(IntremeIndedSpaceSize>0)
>                             {
>floatWordPositionX-=floatWordWidth+floatJustifedSpaceSize+1;
> 
>IntremeIndedSpaceSize--;
>                             }
>否则
>                             {
>floatWordPositionX-=floatWordWidth+floatJustifedSpaceSize;
>                             }
>                         }
>                     }
>                 }
>否则
>                 {
>if(IntLangDirection==(int)applicationschool.LangDirection.LTR)
>                     {
>canvas.DrawText(stringLine,0,floatWordPositionY,textPaint);
>                     }
>如果(IntLangDirection==(int)应用程序学校