我正在使用捏合缩放来水平缩放我的自定义 View 。它工作正常,但外部 ScrollView 未随其内容调整大小,并且 View 周围有难看的空白区域。
我的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<AbsoluteLayout
android:id="@+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="0px"
android:layout_weight="1">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:fillViewport="true"
android:id="@+id/scrollview">
<Auda.WaveFormView
android:id="@+id/waveform"
android:layout_height="fill_parent"
android:layout_width="2000dp"
android:layout_weight="1" />
</HorizontalScrollView>
</AbsoluteLayout>
<LinearLayout
style="@style/ToolbarBackground"
android:layout_width="fill_parent"
android:layout_height="62dip"
android:gravity="center">
<ImageButton
android:id="@+id/play"
android:layout_width="71dip"
android:layout_height="52dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
style="@android:style/MediaButton"
android:src="@android:drawable/ic_media_play" />
</LinearLayout>
我的缩放代码
ScaleAnimation scaleAnimation = new ScaleAnimation(1f / prevScale, 1f / mScale, 1, 1, 0, 0);
scaleAnimation.Duration = 0;
scaleAnimation.FillAfter = true;
this.view.StartAnimation (scaleAnimation);
最佳答案
虽然您的 View 现在(例如)绘制在屏幕的一半上,但它实际上仍然占据了整个屏幕。您可以通过向 View 添加 ClickListener 并尝试按下您标记的空白区域来验证这一点。
要解决这个问题,您可以添加 AnimationListener到你的 ScaleAnimation。在onAnimationEnd
,只需更新 Auda.WaveFormView 的 LayoutParams。例如:
ScaleAnimation scaleAnimation = new ScaleAnimation(1f / prevScale, 1f / mScale, 1, 1, 0, 0);
scaleAnimation.Duration = 0;
scaleAnimation.FillAfter = true;
this.view.StartAnimation (scaleAnimation);
//after your are done with your animation
//set the animation listener
scaleAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
//this might not be the right logic
//especially that you are using scales relative to prevScale
this.view.getLayoutParams().width = v.getWidth() / mScale;
}
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
});
关于android - ScrollView 不调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20140438/