android - ScrollView 不调整大小

标签 android android-layout resize scrollview pinchzoom

我正在使用捏合缩放来水平缩放我的自定义 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);

Screenshot

最佳答案

虽然您的 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/

相关文章:

java - Android 拉动刷新空进度(无箭头)

java - 在android中,如何在 ListView 上使用xml pull解析器显示xml文件中的数据?

android - 无法启动 uiautomatorviewer

ffmpeg - 在 ffmpeg 流上分屏和调整大小

jquery - 检测窗口宽度变化但不检测高度变化

Android软键盘-需要Android软键盘源码AOSP

java - 使用 sax 解析器和 imageloader 类将图像解析为 listview

android - 自定义格式编辑文本输入android接受信用卡号

android - 如何让ImageView与2个Button部分重叠?

java - 我需要我的 textView 在一行中适合屏幕。 android 中是否有类似 autoResize 的功能?