我正在为录制的音频制作可视化图表。我有一个自定义的可视化视图。可视化(仅图形)源自振幅并保持移动并且可以超出屏幕宽度。所以我在HorizontalScrollView
内引入了自定义视图。该视图现在可以滚动。但是一旦图形坐标超出屏幕,它就不会自动滚动。因此,在呈现可视化之后,我引入了smoothscrollby
或smoothscrollto
。但这会导致自定义视图被删除。滚动条移动但是当它超出屏幕宽度时,条形图也会消失。为什么smoothScrollby
删除了什么?它是一个绿色的图形,在末尾绘制一条红线。当我smoothscrollby
时,它会完全消失。我把它放在mHorizontalScrollView.post (new runnable)
但是也没有用。我已经包含了代码和content_recording.xml
如果需要更多信息,请告诉我。
自定义视图代码的一部分
@Override
public void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure( 1999999999, heightMeasureSpec);
}
@Override
public void onDraw (Canvas canvas) {
final int middle = viewHeight / 2; //middle of view
float curX = 0; //start cursor at x axist at 0
//for each item in amplitudes Arraylist
for (float power : amplitudes) {
float scaledHeight = power / LINE_SCALE; //scale the power
curX += LINE_WIDTH; //imcrease by line widht
// draw a line representing this item in the amplitudes ArrayList
canvas.drawLine(curX, middle + scaledHeight / 2, curX, middle - scaledHeight / 2, linePaint);
}
lastAmplitudeIndex = amplitudes.size();
canvas.drawLine(curX, middle + viewHeight / 2, curX, middle - viewHeight / 2, currentLinePointer);
mHorizontalScrollView.smoothScrollBy((int) curX, 0);
}
Content_recording:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Chronometer
android:id="@+id/chronometer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:gravity="center_horizontal"
android:text="@string/chronometer"
android:textAllCaps="true"
android:textColor="@color/colorAccent"
android:textSize="50sp"
android:textStyle="bold" />
<HorizontalScrollView
android:id ="@+id/horscrollview"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:scrollbars="horizontal"
android:layout_margin="5dp"
android:layout_marginTop="25dp"
android:fillViewport="true"
android:scrollbarSize="10dp"
android:scrollbarAlwaysDrawHorizontalTrack="true"
>
<com.example.tasv.musicandroidactivity.VisualizerView
android:id="@+id/visualizer"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</HorizontalScrollView>
</LinearLayout>