我有一个自定义视图,我曾经用它绘制不同的大小和图像到画布.这很棒.所以每次我绘制的东西我都会将这些信息添加到actionList中.
当用户退出应用程序时,我将此actionList作为字符串保存到sharedPreference.在用户重新打开应用程序时,我获取此数据并使用Gson将其转换回List previous_drawn_paths并使用此更新actionList.
当我这样做时,我得到分段错误,但有数据和内存参考.我也附加了代码和tombstone logcat.
DrawingView.java
public class DrawingView extends View {
public enum Type {
PATH,
TEXT,
STAMP;
}
/**
* Different type of draw
*/
public enum Mode {
DRAW,
ERASER,
TEXT,
STAMP;
}
/**
* Different Modes for Drawing
*/
public enum Drawer {
PEN,
LINE,
ELLIPSE;
}
/**
* Different Modes of Stamps
*/
public enum Stamper {
STAR,
THUMB;
}
private Context context = null;
private Canvas canvas = null;
private Bitmap bitmap = null; …Run Code Online (Sandbox Code Playgroud) 我有,我有一个Android的布局设计,AppBar其中将包含一个布局Toolbar和一个更LinearLayout设计有圆形Drawable的TextView.这是相同的高度.因此,当我尝试获得Toolbar或AppBar高度/宽度时,它仅返回0.
activity_main.xml中:
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorPrimary"
app:layout_scrollFlags="enterAlways" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_gravity="center_horizontal"
android:background="@color/colorPrimary"
android:orientation="horizontal"
app:layout_scrollFlags="enterAlways">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/marked_questions"
style="@style/textview_summary_omr_toolbar_count"
android:background="@drawable/bg_percentage_default"
android:text="18" />
<TextView
style="@style/textview_heading_summary_omr_toolbar"
android:text="Marked" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/correct"
style="@style/textview_summary_omr_toolbar_count"
android:background="@drawable/bg_percentage_6"
android:text="18"
/>
<TextView
style="@style/textview_heading_summary_omr_toolbar"
android:text="Correct" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView …Run Code Online (Sandbox Code Playgroud) **注意:(对于书呆子)请勿将其标记为重复的问题.
NullPointerException.view.getDrawingCache从Stackoverflow返回null答案.我正在尝试单独为平板电脑开发绘图应用程序.我创建了一个用于绘图的自定义视图.自定义视图包含在内部ScrollView以使用户滚动图像(如果它太大).
activity_drawing.xml
<RelativeLayout
android:id="@+id/container"
android:layout_marginLeft="@dimen/activity_correction_answer_horizontal_margin"
android:layout_marginRight="@dimen/activity_correction_answer_horizontal_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<in.com.hourglass.views.ImageScroll
android:layout_centerInParent="true"
android:id="@+id/image_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<in.com.hourglass.views.DrawView
android:id="@+id/draw_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</in.com.hourglass.views.ImageScroll>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
因此,当完成视图上的绘图时,用户可以保存图像并进行思考Canvas.
我正在调整图像大小并将其附加到自定义视图Bitmap,并将它们保存为单个图像.整个过程很好用三星平板电脑10.1.
但是当我尝试在较低屏幕设备samsung Note 8.0中测试相同的时候.view.getDrawingCache()给我一个空的Bitmap.
我已经调试并检查了自定义视图的宽度和高度,它们指定了宽度和高度的scrollview,并且customview中也有一个位图.
我Bitmap尽可能地重用以减少app堆内存使用量.
我知道,我必须对此警告采取措施:
W/View: View too large to fit into drawing cache, needs 4380332 bytes, only 4096000 available
Run Code Online (Sandbox Code Playgroud)
错误日志:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: …Run Code Online (Sandbox Code Playgroud)