文本视图中的行在Android应用程序的屏幕截图中消失

时间:2017-08-01 10:48:01

标签: android

在Android应用中,我有一个带有几个按钮的屏幕,TextViewImageView。在执行期间拍摄的此屏幕的屏幕截图(“.jpg”文件)中,仅捕获TextView中的第一个和第二个文本行。有趣的是,最后一个屏幕截图包含TextView的所有行。

有人可以提出原因和适当的补救措施吗?

屏幕顶部有3个按钮(在拍摄屏幕之前不可见),然后TextView和ImageView位于底部。

---------------------布局文件(solveallline1.xml)------------------ ------

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".SolveLine1" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="*" >
            <TableRow>
                <Button
                    android:id="@+id/b_prev"
                    android:enabled="false"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Previous Step" />
                <Button
                    android:id="@+id/b_next"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Next Step" />
                <Button
                    android:id="@+id/b_exit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Exit" />
            </TableRow>
        </TableLayout>
        <TextView
            android:id="@+id/DrawingTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <ImageView
            android:id="@+id/DrawingImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </ImageView>
    </LinearLayout>
</RelativeLayout>

代码中有13个步骤。在每个步骤结束后,拍摄屏幕截图。每个屏幕截图中ImageView的高度根据前一个屏幕截图的TextView中的文本行数而变化。因此,如果与先前的屏幕截图相比,每个屏幕截图的TextView中的线条数量都会被截断。 (例如,步骤11的屏幕截图仅显示2个文本行,因为step10在TextView中有2个文本行)

-----------在步骤10&amp ;;中调用屏幕截图功能的代码11:-----------

void drawStep10(){
        p1=getPaint(p1,"white",getStokeWidth(pxl),getTextSize(pxl),false);
        canvas.drawText("Step9", brx / 4, bry - pxl*2/100, p1);
        p1=getPaint(p1,"black",getStokeWidth(pxl),getTextSize(pxl),false);
        canvas.drawText("a'",aa_dash.x+pxl*3/100,aa_dash.y+pxl*5/100,p1);
        canvas.drawText("b1'",b1_dash.x-pxl*7/100,b1_dash.y+pxl*5/100,p1);
        aaa_dash.drawLn(canvas,p1,a,aa_dash);
        b1b1_dash.drawLn(canvas,p1,b1,b1_dash);
        p1=getPaint(p1,"blue",getStokeWidth(pxl),getTextSize(pxl),false);
        canvas.drawText("Step10", brx / 4, bry - pxl*2/100, p1);
        len4=b1_dash.x-aa_dash.x;
        alfa = (float)Math.asin((d.y-q.y)/(float)len4);
        dalfa = (float)Math.toDegrees(alfa);//alfa in degrees
        len5 = len4*Math.cos(alfa);
        ilen5 = Integer.valueOf(len5.intValue());
        b2_dash = new Point(aa_dash.x+ilen5,q.y);
        RectF oval = new RectF();
        oval.set(aa_dash.x-len4,aa_dash.y-len4,aa_dash.x+len4,aa_dash.y+len4);
        canvas.drawArc(oval,0,dalfa*(-1),false,p1);
        canvas.drawText("b2'",b2_dash.x+pxl*3/100,b2_dash.y+pxl*5/100,p1);
        p1=getPaint(p1,"red",getStokeWidth(pxl),getTextSize(pxl),false);
        canvas.drawLine(aa_dash.x,aa_dash.y,b2_dash.x,b2_dash.y,p1);
        canvas.drawText("<-- center", aa_dash.x+pxl*1/100, aa_dash.y+pxl*1/100, p1);
        canvas.drawText("<-- radius", ((aa_dash.x+b2_dash.x)/2)+pxl*2/100,(aa_dash.y+b2_dash.y)/2, p1);
        drawingTextView.setText("Draw an Arc b1'b2' with Point a' as center. The Arc b1'b2'" +
                " intersects Line pq at Point b2'");
        drawingImageView.invalidate();
        takeScreenshot("Step10");
    }
void drawStep11(){
        p1=getPaint(p1,"white",getStokeWidth(pxl),getTextSize(pxl),false);
        canvas.drawText("Step10", brx / 4, bry - pxl*2/100, p1);
        canvas.drawLine(aa_dash.x,aa_dash.y,b2_dash.x,b2_dash.y,p1);
        canvas.drawText("<-- center", aa_dash.x+pxl*1/100, aa_dash.y+pxl*1/100, p1);
        canvas.drawText("<-- radius", ((aa_dash.x+b2_dash.x)/2)+pxl*2/100,(aa_dash.y+b2_dash.y)/2, p1);
        p1=getPaint(p1,"black",getStokeWidth(pxl),getTextSize(pxl),false);
        RectF oval = new RectF();
        oval.set(aa_dash.x-len4,aa_dash.y-len4,aa_dash.x+len4,aa_dash.y+len4);
        canvas.drawArc(oval,0,dalfa*(-1),false,p1);
        canvas.drawText("b2'",b2_dash.x+pxl*3/100,b2_dash.y+pxl*5/100,p1);
        p1=getPaint(p1,"blue",getStokeWidth(pxl),getTextSize(pxl),false);
        canvas.drawText("Step11", brx / 4, bry - pxl*2/100, p1);
        aa_dashb2_dash = new Line();
        aa_dashb2_dash.drawLn(canvas,p1,aa_dash,b2_dash);
        p1=getPaint(p1,"green",getStokeWidth(pxl),getTextSize(pxl),false);
        canvas.drawText("<-- ϴ =" + theta, adx+pxl*4/100, ady , p1);
        canvas.drawText("<-- Φ =" + phi, a.x+pxl*4/100, a.y+pxl*3/100 , p1);
        canvas.drawText("<-- α =" + Math.floor(dalfa * 100) / 100, aa_dash.x+pxl*4/100, aa_dash.y , p1);
        drawingTextView.setText("Draw a Line a'b2'. Measure Angle b1'a'b2'(α)= " +
                Math.floor(dalfa * 100) / 100+"\n"+
                "Note4:Line a'b2' is the projection of line and is the Front View of the line" +
                " making an angle Φ = "+ phi+" with VP and ϴ = "+theta+" with HP. Angle α = " +
                Math.floor(dalfa * 100) / 100+
                " is made by the projection of the line with HP");
        drawingImageView.invalidate();
        takeScreenshot("Step11");
    }

-----------------截图功能:-------------------------- -

private void takeScreenshot(String s1) {
        try {
            String mPath = Environment.getExternalStorageDirectory().toString() + "/" + s1 + ".jpg";
            View v1 = getWindow().getDecorView().getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmap b1 = Bitmap.createBitmap(v1.getDrawingCache());
            v1.setDrawingCacheEnabled(false);
            imageFile = new File(mPath);
            FileOutputStream outputStream = new FileOutputStream(imageFile);
            int quality = 100;
            b1.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
            outputStream.flush();
            outputStream.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
        }
    }

0 个答案:

没有答案