2 回答
TA贡献1963条经验 获得超6个赞
请详细说明问题或尝试添加代码。
如果您不使用 FrameLayout,请使用它。
添加 FrameLayout 的代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/your_placeholder"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></FrameLayout>
</android.support.constraint.ConstraintLayout>
要添加或替换新片段,请使用 FragmentTransaction。
// Code inside the onCreate method
getSupportFragmentManager().beginTransaction()
.replace(R.id.your_placeholder, new TheOtherFragment())
.commit();
拍摄屏幕截图:
View view = findViewById(R.id.your_placeholder);
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap screenshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
TA贡献2080条经验 获得超4个赞
拍摄屏幕截图:
View view = findViewById(R.id.id_of_constraintLayout);
// Here you assign the view Variable to the id of the View hosting all your Views.
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap screenshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
添加回答
举报