我正在尝试从Android中心开始慢慢填充圆圈的背景
下面是我发现here的示例代码段,我正在尝试执行与下面的代码段完全相同的操作,但在Android中不在网络上。我试图谷歌它,但我只得到结果,如使用TransitionDrawable从颜色更改为颜色,这不是我想要的
$('div').click(function() {
$(this).toggleClass('selected');
});
div.button {
height: 27px;
width: 27px;
border-radius: 50%;
background: green;
}
div.button:after {
content: ''; /* needed for rendering */
position: relative;
display: block; /* so we can set width and height */
border-radius: 50%;
height: 0%;
width: 0%;
margin: auto; /* center horizontally */
background: red;
top: 50%; /* center vertically */
transform: translateY(-50%); /* center vertically */
transition: 1s;
}
div.button.selected:after {
height: 100%;
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="button">
</div>
答案 0 :(得分:1)
尝试以下
在你的活动java
中 circle2 = (ImageView) findViewById(R.id.circle2);
ScaleAnimation fade_in = new ScaleAnimation(0f, 1f, 0f, 1f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
fade_in.setDuration(1000); // animation duration in milliseconds
fade_in.setFillAfter(true); // If fillAfter is true, the transformation that this animation performed will persist when it is finished.
circle2.startAnimation(fade_in);
活动xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/circle" />
<ImageView
android:id="@+id/circle2"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/circle_two" />
</FrameLayout>
在你的drawable circle.xml中
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="@color/colorAccent" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="@color/colorAccent" />
</shape>
</item>
</selector>
同样创建circle2.xml