2013-08-28 24 views
5

Tôi đang tạo hiệu ứng động một ImageView bằng cách sử dụng hình ảnh động quy mô như sau:Scaling hình ảnh động trên một cái nhìn đã có quy mô

<?xml version="1.0" encoding="utf-8"?> 

<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <scale 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:fromXScale="1.0" 
     android:toXScale="2.0" 
     android:fromYScale="1.0" 
     android:toYScale="2.0" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:duration="1000" /> 

    <scale 
     android:interpolator="@android:anim/accelerate_interpolator" 
     android:fromXScale="2.0" 
     android:toXScale="0.0" 
     android:fromYScale="2.0" 
     android:toYScale="0.0" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:startOffset="1000" 
     android:duration="1000" /> 

    <rotate xmlns:android="http://schemas.android.com/apk/res/android" 
     android:fromDegrees="0" 
     android:interpolator="@android:anim/linear_interpolator" 
     android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" 
     android:repeatCount="3" 
     android:duration="800" android:startOffset="0" /> 
</set> 

Nhưng vấn đề là các ImageView đã được thu nhỏ lại bởi cách bố trí, khi hoạt hình đầu tiên bắt đầu. Điều này dẫn đến một bước nhảy đáng chú ý về kích thước, khi hoạt ảnh đầu tiên đặt tỷ lệ thành 1.0.

Có cách nào để nói hoạt ảnh mà nó sẽ bắt đầu từ kích thước thực tế của chế độ xem trong bố cục không? Tôi cũng đã thử làm việc với tỷ lệ phần trăm, tạo ra hiệu ứng tương tự.

Trả lời

0

tôi không tìm thấy một cách sử dụng xml, vì vậy tôi đã kết thúc sử dụng phương pháp này để xác định kích thước trong thời gian chạy và thiết lập hình ảnh động trong Java:

Determining the size of an Android view at runtime

2

Từ những gì tôi hiểu được từ truy vấn của bạn là bạn muốn làm cho hoạt ảnh mượt mà hơn, bằng cách tránh hoạt ảnh quy mô rõ ràng đáng chú ý lúc đầu. Tôi nghĩ rằng giảm thiểu 'từ quy mô' trong quy mô đầu tiên sẽ giúp bạn tránh được những bước nhảy, có lẽ một cái gì đó như thế này sẽ giúp:

<?xml version="1.0" encoding="utf-8"?> 

<scale 
    android:duration="1000" 
    android:fromXScale="0.5" 
    android:fromYScale="0.5" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:toXScale="1.0" 
    android:toYScale="1.0" /> 
<scale 
    android:duration="1000" 
    android:fromXScale="1.0" 
    android:fromYScale="1.0" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:startOffset="1000" 
    android:toXScale="1.0" 
    android:toYScale="1.0" /> 

<rotate 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="800" 
    android:fromDegrees="0" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:repeatCount="3" 
    android:startOffset="0" 
    android:toDegrees="360" /> 

Xin lỗi để giữ cho bạn chờ đợi; thử một cái gì đó như thế này:

<?xml version="1.0" encoding="utf-8"?> 

<scale 
    android:duration="400" 
    android:fromXScale="1" 
    android:fromYScale="1" 
    android:pivotX="20%" 
    android:pivotY="20%" 
    android:repeatCount="1" 
    android:repeatMode="reverse" 
    android:toXScale="1.1" 
    android:toYScale="1.1" /> 

+0

Không, những gì tôi đang cố gắng hoàn thành là có ani mở rộng mation bắt đầu không phải từ một giá trị cố định (không phải 0.5 hoặc 1.0), nhưng từ giá trị mở rộng thực tế của ImageView. Điều này là cần thiết, vì tôi không biết kích thước của View sẽ được kích thước trên một thiết bị cụ thể. –

+0

Tôi đã chỉnh sửa câu trả lời của mình. Hãy thử mã này. – Sathya

+0

Cảm ơn bạn, nhưng tôi nghĩ bạn hiểu sai câu hỏi. Vấn đề của tôi là ImageView có thể có bất kỳ quy mô nào ngay từ đầu. Bắt đầu từ một quy mô cố định sẽ tạo ra một bước nhảy đáng chú ý trong hoạt hình, bất kể tôi đặt nó là gì. –