如何在使用动画时在 ImageView 上设置圆角
How to set rounded corner on ImageView while using Animation on it
我有一个像这样的 ImageView 布局:
正如在 imageView 角中提到的那样,当在其上使用动画时它不会保持圆角。
如何在使用动画的同时使其变圆?
布局代码:
<TableLayout
android:layout_width="wrap_content"
android:id="@+id/table1"
android:gravity="center"
android:layout_height="wrap_content">
<TableRow>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/img1_1"
android:background="@drawable/button"
android:layout_margin="3dp"
/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/img1_2"
android:background="@drawable/button"
android:layout_margin="3dp"
/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/img1_3"
android:background="@drawable/button"
android:layout_margin="3dp"
/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/img1_4"
android:background="@drawable/button"
android:layout_margin="3dp"
/>
</TableRow>
</TableLayout>
Java代码:
ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundColor", Color.RED, Color.parseColor("#4caf41")).setDuration(5000);
Toast.makeText(Game.this, "index" + findViewById(id), Toast.LENGTH_LONG).show();
animator.setEvaluator(new ArgbEvaluator());
animator.start();
当动画开始时,您正在按下 Imageview。所以你可以使用
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/numpad_button_bg_selected" android:state_selected="true"></item>
<item android:drawable="@drawable/numpad_button_bg_pressed" android:state_pressed="true"></item>
<item android:drawable="@drawable/numpad_button_bg_normal"></item>
</selector>
按下按钮后使用相同的图像..可能会对您有所帮助..
你可以使用滑行。它还允许您添加动画。
https://futurestud.io/tutorials/glide-custom-animations-with-animate
我已解决此问题以在这一行中进行更改:
ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundColor", Color.RED, Color.parseColor("#4caf41")).setDuration(5000);
像这样:
ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundResource", R.drawable.original_img, R.drawable.org_state).setDuration(2000);
即
我设置了 backgroundResource 而不是 backgroundColor.and 设置了图像而不是 hexcolor 代码。
我有一个像这样的 ImageView 布局:
正如在 imageView 角中提到的那样,当在其上使用动画时它不会保持圆角。
如何在使用动画的同时使其变圆?
布局代码:
<TableLayout
android:layout_width="wrap_content"
android:id="@+id/table1"
android:gravity="center"
android:layout_height="wrap_content">
<TableRow>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/img1_1"
android:background="@drawable/button"
android:layout_margin="3dp"
/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/img1_2"
android:background="@drawable/button"
android:layout_margin="3dp"
/>
</TableRow>
<TableRow>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/img1_3"
android:background="@drawable/button"
android:layout_margin="3dp"
/>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/img1_4"
android:background="@drawable/button"
android:layout_margin="3dp"
/>
</TableRow>
</TableLayout>
Java代码:
ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundColor", Color.RED, Color.parseColor("#4caf41")).setDuration(5000);
Toast.makeText(Game.this, "index" + findViewById(id), Toast.LENGTH_LONG).show();
animator.setEvaluator(new ArgbEvaluator());
animator.start();
当动画开始时,您正在按下 Imageview。所以你可以使用
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/numpad_button_bg_selected" android:state_selected="true"></item>
<item android:drawable="@drawable/numpad_button_bg_pressed" android:state_pressed="true"></item>
<item android:drawable="@drawable/numpad_button_bg_normal"></item>
</selector>
按下按钮后使用相同的图像..可能会对您有所帮助..
你可以使用滑行。它还允许您添加动画。
https://futurestud.io/tutorials/glide-custom-animations-with-animate
我已解决此问题以在这一行中进行更改:
ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundColor", Color.RED, Color.parseColor("#4caf41")).setDuration(5000);
像这样:
ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundResource", R.drawable.original_img, R.drawable.org_state).setDuration(2000);
即
我设置了 backgroundResource 而不是 backgroundColor.and 设置了图像而不是 hexcolor 代码。