【问题标题】:ImageView scale up animation cuts off imageImageView 放大动画切断图像
【发布时间】:2014-07-26 14:17:19
【问题描述】:

在我的应用程序中,我想为一个扩展至其大小约 120% 的图标设置动画。问题是,当我这样做时,ImageView 的内容会被截断。有什么办法让它不会发生这种情况吗?

动画的调用:

Animation sgAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.highlight);
charm.startAnimation(sgAnimation);

动画本身:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillBefore="true"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true" >

<scale
    android:duration="100"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:toXScale="1.5"
    android:toYScale="1.5" />
</set>

以及与图像视图有关的布局部分:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/over_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     >        
<RelativeLayout
    android:id="@+id/charms_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="15dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp" >

    <ImageView
        android:id="@+id/charm_phone"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:alpha=".75"
        android:contentDescription="@string/account_image_description"
        android:src="@drawable/ic_phone_white_24dp" />

    <ImageView
        android:id="@+id/charm_lock"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:contentDescription="@string/account_image_description"
        android:src="@drawable/ic_qs_lock_screen_off" />

    <ImageView
        android:id="@+id/charm_camera"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:alpha=".75"
        android:contentDescription="@string/account_image_description"
        android:src="@drawable/ic_camera_white_24dp" />

注意:我已经尝试将 24dp 替换为 wrap_content,但没有成功

【问题讨论】:

    标签: android android-imageview android-animation


    【解决方案1】:

    我会尝试使用

    android:clipChildren="false"
    android:clipToPadding="false" 
    

    在你的 imageView 容器和你的 imageview 中

    【讨论】:

    • 你能发布你的布局吗?
    • 添加容器并将其自身查看到原始帖子
    • 所以您尝试了然后删除了我建议的属性,因为它们不能正常工作?
    • 是的,我尝试将您建议的两个属性添加到 relativelayout 和 imageview
    • 是否有另一个布局包含相对布局或者这是根?
    【解决方案2】:

    所以我最终为图像视图添加了填充,并通过额外的填充增加了图像视图的大小。这样,当它被动画化时,它会在填充空间中动画化并且不会被裁剪。

    【讨论】:

      【解决方案3】:

      根据缩放动画给ImageView的父布局高度,你可以达到预期的效果。

      在您的情况下,您正在尝试为宽度和高度为 24dp 的 ImageView 设置动画。因此,您将需要一个 36dp 的空间,以便 ImageView 正确设置动画。由于您将布局宽度指定为 match_parent,因此您的图像没有从左右两侧切割,但高度的包装内容不起作用。

      考虑一张图片:

      <RelativeLayout
          android:id="@+id/relative_layout"
          android:layout_width="match_parent"
          android:layout_height="36dp">
      
          <ImageView
              android:id="@+id/image_view"
              android:layout_width="24dp"
              android:layout_height="24dp"
              android:layout_margin="6dp"
              android:layout_alignParentLeft="true"
              android:src="@drawable/src_image"/>
      
      <RelativeLayout/>
      

      【讨论】:

        猜你喜欢
        • 2012-07-10
        • 1970-01-01
        • 1970-01-01
        • 2020-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多