2013-11-22 109 views
3

我正在使用縮放縮放來縮放我的自定義視圖。它可以正常工作,但外部滾動視圖不會調整其內容大小,視圖周圍有一個醜陋的空白區域。滾動查看不調整大小

我的佈局

<?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

+0

爲什麼你使用'AbsoluteLayout'改變佈局寬度FILL_PARENT而不是包裝內容? [從API 3開始已被棄用](http://developer.android.com/reference/android/widget/AbsoluteLayout.html)。您應該改用[RelativeLayout](http://developer.android.com/reference/android/widget/RelativeLayout.html)。 – taylorstine

+0

我將它改爲RelativeLayout,但仍然遇到同樣的問題。 –

回答

0

儘管現在已經繪製在屏幕的一半的視圖(例如),它是真的仍然佔據了整個屏幕。您可以通過將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) {} 
}); 
+0

設置LayoutParams不起作用。返回的寬度是-2或0,它不會更改視圖的寬度(滾動條不會調整大小) –

+0

我修復了它。改用getWidth –