0

我正在开发一个 Android 应用程序,它记录来自麦克风的数据并进行实时音高检测并将音高值绘制为图形。到目前为止,我已经完成了实时的音高检测。现在我想将这些值动态地绘制为图表。所以我的应用程序的屏幕应该有 2 个片段。一个有记录和停止按钮,我想在另一个片段中显示我的图表。我已经了解如何使用 AChartEngine 实时绘制 graoh。我还了解了使用片段的基础知识。所以我的问题是,我如何将所有这些连接在一起?即,我想运行我的音高检测活动,并在单击“记录”按钮时动态显示图形,并在单击“停止”按钮时停止整个事情。是否有任何示例代码显示通过单击一个片段中的按钮在另一个片段上绘制图形?谢谢!

4

2 回答 2

0

使用 ScrollView 喜欢:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollViewChartContainer" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:id="@+id/main" android:layout_width="fill_parent" android:layout_height="match_parent">
       <LinearLayout android:id="@+id/chart1" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:orientation="horizontal" /> 
       <LinearLayout android:id="@+id/chart2" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:orientation="horizontal" /> 
    </LinearLayout>
</ScrollView>

我没有测试过这样的布局,但它应该可以工作。

于 2013-03-12T08:00:13.270 回答
0

这只是我的想法。您可以做的是,设置两个片段,创建一些用于显示和提供数据给片段的方法(如果fragment.setArgs()不足以满足您的需要)

想象一下,你有你SecondFragment喜欢的方法,当你点击 Stop 时调用它,你从后面的堆栈中取出第二个片段:

public void showRecordedData(SomeDataModel data){
     this.mFragmentData = data;
     ///show the  data on the chart view of the second fragment
}

确保SecondFragment不为空且可见。

希望这是有道理的。

于 2013-03-07T14:55:11.983 回答