Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.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
Java 绘制到画布上的位图,其中包含已设置为“已消失”的视图的空间_Java_Android_Bitmap_Visibility - Fatal编程技术网

Java 绘制到画布上的位图,其中包含已设置为“已消失”的视图的空间

Java 绘制到画布上的位图,其中包含已设置为“已消失”的视图的空间,java,android,bitmap,visibility,Java,Android,Bitmap,Visibility,我真的很难从我的活动滚动视图中创建一个位图,它没有“空白”来容纳我设置为已消失的视图。 我在代码流的不同阶段尝试过setVisibility(View.GONE),但都会生成一个位图,其中的视图显示为不可见 public class Example extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState)

我真的很难从我的活动滚动视图中创建一个位图,它没有“空白”来容纳我设置为已消失的视图。 我在代码流的不同阶段尝试过setVisibility(View.GONE),但都会生成一个位图,其中的视图显示为不可见

public class Example extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.myActivity);

Button button = findViewById(R.id.myButton);
button.setOnClickListener(new ViewOnClickListener() {
@Overide
public void onClick(View view){
ScrollView scrollView = findViewById(R.id.myScrollView);
TableLayout tableLayout = findViewById(R.id.myTableLayout);
tableLayout.setVisibility(View.GONE);
Bitmap bitmap = Bitmap.createBitmap(scrollView.getChildAt(0).getWidth(),scrollView.getChildAt(0).getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
scrollView.draw(canvas);
PrintHelper printHelper = new PrintHelper(Example.this);
printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT);
PrintHelper.printBitmap("myFileName", bitmap);
}
}
);
}
我试过各种各样的东西,比如:

  • 将TableLayout设置为GONE,然后再次将TableLayout创建为VISIBLE,然后单击返回GONE按钮
  • 使用LayoutParams将TableLayout高度设置为0
  • scrollView.removeView(表格布局)
  • 将TableLayout和每个内容设置为可见性
  • 什么都不管用。 我将在下面添加xml代码,以便您可以剪切和粘贴并自己尝试。 空白区域的“TextView”和“TextView2”之间仍有一个间隙,即TableLayout(具有TextView 3和4)的位置,即视图不可见且未消失

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/myScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".Example">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView"
                android:textSize="24sp" />
            <TableLayout
                android:id="@+id/myTableLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TableRow>
                    <TextView
                        android:id="@+id/textView3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="TextView3" />
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/textView4"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="TextView4" />
                </TableRow>
            </TableLayout>
            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView2"
                android:textSize="24sp" />
            <Button
                android:id="@+id/myButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </LinearLayout>
    </ScrollView>
    
    
    
    提前谢谢