android新图 android-全屏 activity 不填满屏幕
androidplot with new android-full-screen activity does not fill screen
全屏好像有两种定义
android全屏=没有任务栏,没有状态栏或按钮,只是填满屏幕
android plot full-screen = 左右和底部没有图例,只是一个全屏图形小部件
此问题与 Android 全屏有关,滑动操作可使任务栏和按钮栏隐藏(全屏)或显示...它不会扩展(填充)图表部分一直到底部的图例
以下内容基于Android剧情1.4.3
创建一个空 activity 的新 android studio 2.3.2 项目并将 Android 情节演示应用程序的 "simple xy plot" java 代码复制到 onCreate布局 xml 文件中的 xml 部分工作正常,图形部分一直扩展到底部图例
创建一个新的 android studio 2.3.2 全屏项目 activity(滑动到 hide/show 任务栏和按钮栏)设置无法展开图表部分向下到底部图例
android studio 生成的默认 activity 代码框架现在比第一个空 activity
示例更复杂
带有“// zzz ...”的行表示与 android 工作室生成的代码有偏差
全屏activityjava代码开始
package com.efilabs.plotxynew;
import android.annotation.SuppressLint;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import com.androidplot.xy.XYPlot;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*/
public class ActPlotNew0 extends AppCompatActivity
{
/**
* Whether or not the system UI should be auto-hidden after
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
*/
private static final boolean AUTO_HIDE = true;
/**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
* user interaction before hiding the system UI.
*/
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
/**
* Some older devices needs a small delay between UI widget updates
* and a change of the status and navigation bar.
*/
private static final int UI_ANIMATION_DELAY = 300;
private final Handler mHideHandler = new Handler ();
private View mContentView; // zzz
//private XYPlot mContentView; // zzz
private final Runnable mHidePart2Runnable = new Runnable ()
{
@SuppressLint ("InlinedApi")
@Override
public void run ()
{
// Delayed removal of status and navigation bar
// Note that some of these constants are new as of API 16 (Jelly Bean)
// and API 19 (KitKat). It is safe to use them, as they are inclined
// at compile-time and do nothing on earlier devices.
mContentView.setSystemUiVisibility (View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
};
private View mControlsView;
private final Runnable mShowPart2Runnable = new Runnable ()
{
@Override
public void run ()
{
// Delayed display of UI elements
ActionBar actionBar = getSupportActionBar ();
if (actionBar != null) {
actionBar.show ();
}
mControlsView.setVisibility (View.VISIBLE);
}
};
private boolean mVisible;
private final Runnable mHideRunnable = new Runnable ()
{
@Override
public void run ()
{
hide ();
}
};
/**
* Touch listener to use for in-layout UI controls to delay hiding the
* system UI. This is to prevent the jarring behavior of controls going away
* while interacting with activity UI.
*/
private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener ()
{
@Override
public boolean onTouch (View view, MotionEvent motionEvent)
{
if (AUTO_HIDE) {
delayedHide (AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.act_plotnew0);
mVisible = true;
mControlsView = findViewById (R.id.fullscreen_content_controls);
mContentView = findViewById (R.id.fullscreen_content); // zzz
// mContentView = (XYPlot) findViewById (R.id.fullscreen_content); // zzz
// Set up the user interaction to manually show or hide the system UI.
mContentView.setOnClickListener (new View.OnClickListener ()
{
@Override
public void onClick (View view)
{
toggle ();
}
});
// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
findViewById (R.id.dummy_button).setOnTouchListener (mDelayHideTouchListener);
}
@Override
protected void onPostCreate (Bundle savedInstanceState)
{
super.onPostCreate (savedInstanceState);
// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
delayedHide (100);
}
private void toggle ()
{
if (mVisible) {
hide ();
} else {
show ();
}
}
private void hide ()
{
// Hide UI first
ActionBar actionBar = getSupportActionBar ();
if (actionBar != null) {
actionBar.hide ();
}
mControlsView.setVisibility (View.GONE);
mVisible = false;
// Schedule a runnable to remove the status and navigation bar after a delay
mHideHandler.removeCallbacks (mShowPart2Runnable);
mHideHandler.postDelayed (mHidePart2Runnable, UI_ANIMATION_DELAY);
}
@SuppressLint ("InlinedApi")
private void show ()
{
// Show the system bar
mContentView.setSystemUiVisibility (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
mVisible = true;
// Schedule a runnable to display UI elements after a delay
mHideHandler.removeCallbacks (mHidePart2Runnable);
mHideHandler.postDelayed (mShowPart2Runnable, UI_ANIMATION_DELAY);
}
/**
* Schedules a call to hide() in [delay] milliseconds, canceling any
* previously scheduled calls.
*/
private void delayedHide (int delayMillis)
{
mHideHandler.removeCallbacks (mHideRunnable);
mHideHandler.postDelayed (mHideRunnable, delayMillis);
}
}
全屏activityjava代码结束
XML 布局包含插入的 android 绘图视图部分
全屏activity布局XML开始
<FrameLayout 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"
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:background="#0099cc"
tools:context="com.efilabs.plotxynew.ActPlotNew0">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<!--TextView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="@string/dummy_content"
android:textColor="#33b5e5"
android:textSize="50sp"
android:textStyle="bold"/-->
<com.androidplot.xy.XYPlot
style="@style/APDefacto.Light"
android:id="@+id/fullscreen_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ap:title="A Simple XY Plot"
ap:rangeTitle="range"
ap:domainTitle="domain"
ap:lineLabels="left|bottom"
ap:lineLabelRotationBottom="-45"/>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="@+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/dummy_button"/>
</LinearLayout>
</FrameLayout>
</FrameLayout>
全屏activity布局XML结束
为了不混淆 Android 生成的 java 代码,我创建了第二个 java activity class 扩展了 Android 生成的java activity 代码并将 "simple XY plot" 放入其中
扩展activity代码开始
package com.efilabs.plotxynew;
import android.graphics.DashPathEffect;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import com.androidplot.util.PixelUtils;
import com.androidplot.xy.CatmullRomInterpolator;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYGraphWidget;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYSeries;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.util.Arrays;
public class ActPlotNew0a extends ActPlotNew0
{
private XYPlot plot;
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
// setContentView (R.layout.act_plotnew0); // xxx provides full screen but swipe doesn't work anylonger
ActionBar bar = getSupportActionBar () ;
if (bar != null) bar.hide () ;
// initialize our XYPlot reference:
plot = (XYPlot) findViewById(R.id.fullscreen_content);
// create a couple arrays of y-values to plot:
final Number[] domainLabels = {1, 2, 3, 6, 7, 8, 9, 10, 13, 14};
Number[] series1Numbers = {1, 4, 2, 8, 4, 16, 8, 32, 16, 64};
Number[] series2Numbers = {5, 2, 10, 5, 20, 10, 40, 20, 80, 40};
// turn the above arrays into XYSeries':
// (Y_VALS_ONLY means use the element index as the x value)
XYSeries series1 = new SimpleXYSeries (
Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");
XYSeries series2 = new SimpleXYSeries(
Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");
// create formatters to use for drawing a series using LineAndPointRenderer
// and configure them from xml:
LineAndPointFormatter series1Format =
new LineAndPointFormatter(this, R.xml.line_point_formatter_with_labels);
LineAndPointFormatter series2Format =
new LineAndPointFormatter(this, R.xml.line_point_formatter_with_labels_2);
// add an "dash" effect to the series2 line:
series2Format.getLinePaint().setPathEffect(new DashPathEffect (new float[]
{
// always use DP when specifying pixel sizes, to keep things consistent across devices:
PixelUtils.dpToPix(20),
PixelUtils.dpToPix(15)
}, 0));
// (optional) add some smoothing to the lines:
// see: http://androidplot.com/smooth-curves-and-androidplot/
series1Format.setInterpolationParams(
new CatmullRomInterpolator.Params(10, CatmullRomInterpolator.Type.Centripetal));
series2Format.setInterpolationParams(
new CatmullRomInterpolator.Params(10, CatmullRomInterpolator.Type.Centripetal));
// add a new series' to the xyplot:
plot.addSeries(series1, series1Format);
plot.addSeries(series2, series2Format);
plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).setFormat(new Format ()
{
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
{
int i = Math.round(((Number) obj).floatValue());
return toAppendTo.append(domainLabels[i]);
}
@Override
public Object parseObject(String source, ParsePosition pos)
{
return null;
}
});
}
}
扩展activity代码结束
有趣的是,取消注释包含“... // xxx ...”的第 28 行使全屏工作,但现在滑动手势可在 hiding/show 任务栏和按钮之间切换-栏”不再有效
我没有足够的经验来解决这个问题,需要一些认真的帮助
注意:上述场景适用于 Android plot 0.9.8,并提供全屏 Android 绘图部分填充到底部图例
this picture shows the additional rectangle portion marked in red which should be filled by the graph widget for full screen
问题的根本原因是在布局和绘制绘图后调用 setSystemUiVisibility(...)
。这在 0.9.8 中不是问题,因为 XYGraphWidget
会在每次绘制时手动重新计算它的尺寸。这是一项昂贵且(通常)不必要的操作,并且出于性能原因在以后的版本中被删除。
我知道这没有解决您的用例(这是一个有效的用例),但如果您摆脱 postDelayed 并将全屏调整代码移至 onCreate,那么全屏模式将正确显示。
我正在为 1.4.5 版本开发图形呈现逻辑的替代实现,希望在支持您的用例的同时避免性能问题。它不应该要求您更改任何代码。
同时,一个简单的解决方法是在 setSystemUiVisibility
之后立即执行以下操作:
plot.getGraph().setGridRect(null);
plot.redraw();
尝试了你的建议,并在第 58 行周围的可运行部分 mContentView.setSystemUiVisibility (...) 之后放置了以下内容
plot.getGraph ().setGridRect (null) ;
plot.getGraph ().setLabelRect (null) ;
plot.redraw () ;
现在可以使用...在此处给出的简化示例中,它需要逐步显示/隐藏/显示,但在我的真实代码中,它可以在打开 activity
关于 "get rid of the postDelayed" 我不太确定如何实现它,我不是像你这样的内部 android 专家......但现在我有一个解决方案这似乎有效
这将在我继续开发周期期间起作用,到我完成时,我希望 1.4.5 将解决这个问题
非常感谢您的快速回复
截至 2018 年 12 月和 android studio 3.2.1 似乎不再需要此修复程序
无法判断此更改何时发生,只是 运行 导致与上述修复相关的空指针异常
没有 gua运行tees ... 刚刚进行了更改,但还有其他不相关的错误需要解决
干杯 efiLabs
全屏好像有两种定义
android全屏=没有任务栏,没有状态栏或按钮,只是填满屏幕
android plot full-screen = 左右和底部没有图例,只是一个全屏图形小部件
此问题与 Android 全屏有关,滑动操作可使任务栏和按钮栏隐藏(全屏)或显示...它不会扩展(填充)图表部分一直到底部的图例
以下内容基于Android剧情1.4.3
创建一个空 activity 的新 android studio 2.3.2 项目并将 Android 情节演示应用程序的 "simple xy plot" java 代码复制到 onCreate布局 xml 文件中的 xml 部分工作正常,图形部分一直扩展到底部图例
创建一个新的 android studio 2.3.2 全屏项目 activity(滑动到 hide/show 任务栏和按钮栏)设置无法展开图表部分向下到底部图例
android studio 生成的默认 activity 代码框架现在比第一个空 activity
示例更复杂带有“// zzz ...”的行表示与 android 工作室生成的代码有偏差
全屏activityjava代码开始
package com.efilabs.plotxynew;
import android.annotation.SuppressLint;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import com.androidplot.xy.XYPlot;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*/
public class ActPlotNew0 extends AppCompatActivity
{
/**
* Whether or not the system UI should be auto-hidden after
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
*/
private static final boolean AUTO_HIDE = true;
/**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
* user interaction before hiding the system UI.
*/
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
/**
* Some older devices needs a small delay between UI widget updates
* and a change of the status and navigation bar.
*/
private static final int UI_ANIMATION_DELAY = 300;
private final Handler mHideHandler = new Handler ();
private View mContentView; // zzz
//private XYPlot mContentView; // zzz
private final Runnable mHidePart2Runnable = new Runnable ()
{
@SuppressLint ("InlinedApi")
@Override
public void run ()
{
// Delayed removal of status and navigation bar
// Note that some of these constants are new as of API 16 (Jelly Bean)
// and API 19 (KitKat). It is safe to use them, as they are inclined
// at compile-time and do nothing on earlier devices.
mContentView.setSystemUiVisibility (View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
};
private View mControlsView;
private final Runnable mShowPart2Runnable = new Runnable ()
{
@Override
public void run ()
{
// Delayed display of UI elements
ActionBar actionBar = getSupportActionBar ();
if (actionBar != null) {
actionBar.show ();
}
mControlsView.setVisibility (View.VISIBLE);
}
};
private boolean mVisible;
private final Runnable mHideRunnable = new Runnable ()
{
@Override
public void run ()
{
hide ();
}
};
/**
* Touch listener to use for in-layout UI controls to delay hiding the
* system UI. This is to prevent the jarring behavior of controls going away
* while interacting with activity UI.
*/
private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener ()
{
@Override
public boolean onTouch (View view, MotionEvent motionEvent)
{
if (AUTO_HIDE) {
delayedHide (AUTO_HIDE_DELAY_MILLIS);
}
return false;
}
};
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.act_plotnew0);
mVisible = true;
mControlsView = findViewById (R.id.fullscreen_content_controls);
mContentView = findViewById (R.id.fullscreen_content); // zzz
// mContentView = (XYPlot) findViewById (R.id.fullscreen_content); // zzz
// Set up the user interaction to manually show or hide the system UI.
mContentView.setOnClickListener (new View.OnClickListener ()
{
@Override
public void onClick (View view)
{
toggle ();
}
});
// Upon interacting with UI controls, delay any scheduled hide()
// operations to prevent the jarring behavior of controls going away
// while interacting with the UI.
findViewById (R.id.dummy_button).setOnTouchListener (mDelayHideTouchListener);
}
@Override
protected void onPostCreate (Bundle savedInstanceState)
{
super.onPostCreate (savedInstanceState);
// Trigger the initial hide() shortly after the activity has been
// created, to briefly hint to the user that UI controls
// are available.
delayedHide (100);
}
private void toggle ()
{
if (mVisible) {
hide ();
} else {
show ();
}
}
private void hide ()
{
// Hide UI first
ActionBar actionBar = getSupportActionBar ();
if (actionBar != null) {
actionBar.hide ();
}
mControlsView.setVisibility (View.GONE);
mVisible = false;
// Schedule a runnable to remove the status and navigation bar after a delay
mHideHandler.removeCallbacks (mShowPart2Runnable);
mHideHandler.postDelayed (mHidePart2Runnable, UI_ANIMATION_DELAY);
}
@SuppressLint ("InlinedApi")
private void show ()
{
// Show the system bar
mContentView.setSystemUiVisibility (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
mVisible = true;
// Schedule a runnable to display UI elements after a delay
mHideHandler.removeCallbacks (mHidePart2Runnable);
mHideHandler.postDelayed (mShowPart2Runnable, UI_ANIMATION_DELAY);
}
/**
* Schedules a call to hide() in [delay] milliseconds, canceling any
* previously scheduled calls.
*/
private void delayedHide (int delayMillis)
{
mHideHandler.removeCallbacks (mHideRunnable);
mHideHandler.postDelayed (mHideRunnable, delayMillis);
}
}
全屏activityjava代码结束
XML 布局包含插入的 android 绘图视图部分
全屏activity布局XML开始
<FrameLayout 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"
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:background="#0099cc"
tools:context="com.efilabs.plotxynew.ActPlotNew0">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<!--TextView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="@string/dummy_content"
android:textColor="#33b5e5"
android:textSize="50sp"
android:textStyle="bold"/-->
<com.androidplot.xy.XYPlot
style="@style/APDefacto.Light"
android:id="@+id/fullscreen_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ap:title="A Simple XY Plot"
ap:rangeTitle="range"
ap:domainTitle="domain"
ap:lineLabels="left|bottom"
ap:lineLabelRotationBottom="-45"/>
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="@+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/dummy_button"/>
</LinearLayout>
</FrameLayout>
</FrameLayout>
全屏activity布局XML结束
为了不混淆 Android 生成的 java 代码,我创建了第二个 java activity class 扩展了 Android 生成的java activity 代码并将 "simple XY plot" 放入其中
扩展activity代码开始
package com.efilabs.plotxynew;
import android.graphics.DashPathEffect;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import com.androidplot.util.PixelUtils;
import com.androidplot.xy.CatmullRomInterpolator;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYGraphWidget;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYSeries;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.util.Arrays;
public class ActPlotNew0a extends ActPlotNew0
{
private XYPlot plot;
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
// setContentView (R.layout.act_plotnew0); // xxx provides full screen but swipe doesn't work anylonger
ActionBar bar = getSupportActionBar () ;
if (bar != null) bar.hide () ;
// initialize our XYPlot reference:
plot = (XYPlot) findViewById(R.id.fullscreen_content);
// create a couple arrays of y-values to plot:
final Number[] domainLabels = {1, 2, 3, 6, 7, 8, 9, 10, 13, 14};
Number[] series1Numbers = {1, 4, 2, 8, 4, 16, 8, 32, 16, 64};
Number[] series2Numbers = {5, 2, 10, 5, 20, 10, 40, 20, 80, 40};
// turn the above arrays into XYSeries':
// (Y_VALS_ONLY means use the element index as the x value)
XYSeries series1 = new SimpleXYSeries (
Arrays.asList(series1Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");
XYSeries series2 = new SimpleXYSeries(
Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");
// create formatters to use for drawing a series using LineAndPointRenderer
// and configure them from xml:
LineAndPointFormatter series1Format =
new LineAndPointFormatter(this, R.xml.line_point_formatter_with_labels);
LineAndPointFormatter series2Format =
new LineAndPointFormatter(this, R.xml.line_point_formatter_with_labels_2);
// add an "dash" effect to the series2 line:
series2Format.getLinePaint().setPathEffect(new DashPathEffect (new float[]
{
// always use DP when specifying pixel sizes, to keep things consistent across devices:
PixelUtils.dpToPix(20),
PixelUtils.dpToPix(15)
}, 0));
// (optional) add some smoothing to the lines:
// see: http://androidplot.com/smooth-curves-and-androidplot/
series1Format.setInterpolationParams(
new CatmullRomInterpolator.Params(10, CatmullRomInterpolator.Type.Centripetal));
series2Format.setInterpolationParams(
new CatmullRomInterpolator.Params(10, CatmullRomInterpolator.Type.Centripetal));
// add a new series' to the xyplot:
plot.addSeries(series1, series1Format);
plot.addSeries(series2, series2Format);
plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).setFormat(new Format ()
{
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
{
int i = Math.round(((Number) obj).floatValue());
return toAppendTo.append(domainLabels[i]);
}
@Override
public Object parseObject(String source, ParsePosition pos)
{
return null;
}
});
}
}
扩展activity代码结束
有趣的是,取消注释包含“... // xxx ...”的第 28 行使全屏工作,但现在滑动手势可在 hiding/show 任务栏和按钮之间切换-栏”不再有效
我没有足够的经验来解决这个问题,需要一些认真的帮助
注意:上述场景适用于 Android plot 0.9.8,并提供全屏 Android 绘图部分填充到底部图例
this picture shows the additional rectangle portion marked in red which should be filled by the graph widget for full screen
问题的根本原因是在布局和绘制绘图后调用 setSystemUiVisibility(...)
。这在 0.9.8 中不是问题,因为 XYGraphWidget
会在每次绘制时手动重新计算它的尺寸。这是一项昂贵且(通常)不必要的操作,并且出于性能原因在以后的版本中被删除。
我知道这没有解决您的用例(这是一个有效的用例),但如果您摆脱 postDelayed 并将全屏调整代码移至 onCreate,那么全屏模式将正确显示。
我正在为 1.4.5 版本开发图形呈现逻辑的替代实现,希望在支持您的用例的同时避免性能问题。它不应该要求您更改任何代码。
同时,一个简单的解决方法是在 setSystemUiVisibility
之后立即执行以下操作:
plot.getGraph().setGridRect(null);
plot.redraw();
尝试了你的建议,并在第 58 行周围的可运行部分 mContentView.setSystemUiVisibility (...) 之后放置了以下内容
plot.getGraph ().setGridRect (null) ;
plot.getGraph ().setLabelRect (null) ;
plot.redraw () ;
现在可以使用...在此处给出的简化示例中,它需要逐步显示/隐藏/显示,但在我的真实代码中,它可以在打开 activity
关于 "get rid of the postDelayed" 我不太确定如何实现它,我不是像你这样的内部 android 专家......但现在我有一个解决方案这似乎有效
这将在我继续开发周期期间起作用,到我完成时,我希望 1.4.5 将解决这个问题
非常感谢您的快速回复
截至 2018 年 12 月和 android studio 3.2.1 似乎不再需要此修复程序
无法判断此更改何时发生,只是 运行 导致与上述修复相关的空指针异常
没有 gua运行tees ... 刚刚进行了更改,但还有其他不相关的错误需要解决
干杯 efiLabs