Android 向以图形方式添加的视图添加涟漪效果
我有一个图像视图,由程序添加为:Android 向以图形方式添加的视图添加涟漪效果,android,android-layout,android-view,android-xml,ripple,Android,Android Layout,Android View,Android Xml,Ripple,我有一个图像视图,由程序添加为: imagen = new ImageView(getApplicationContext()); 现在我想将涟漪效应应用于此。 我有涟漪效应库: <com.skyfishjy.library.RippleBackground xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-aut
imagen = new ImageView(getApplicationContext());
现在我想将涟漪效应应用于此。
我有涟漪效应库:
<com.skyfishjy.library.RippleBackground
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content"
app:rb_color="#0099CC"
app:rb_radius="32dp"
app:rb_rippleAmount="4"
app:rb_duration="3000"
app:rb_scale="6">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerInParent="true"
android:id="@+id/centerImage"
android:src="@drawable/demoImage"/>
</com.skyfishjy.library.RippleBackground>
在上面的代码中,我在XML中有图像视图,但我的图像视图是在运行时创建的,因此如何将涟漪效应应用于运行时Imageview
向以图形方式添加的视图添加涟漪效果
您可以从xml扩展视图,并以编程方式将其添加到容器布局中
View inflatedLayout= getLayoutInflater().inflate(R.layout.my_view, null, false);
container.addView(inflatedLayout);
my_view.xml
<com.skyfishjy.library.RippleBackground
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content"
app:rb_color="#0099CC"
app:rb_radius="32dp"
app:rb_rippleAmount="4"
app:rb_duration="3000"
app:rb_scale="6">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerInParent="true"
android:id="@+id/centerImage"
android:src="@drawable/demoImage"/>
</com.skyfishjy.library.RippleBackground>
向以图形方式添加的视图添加涟漪效果
您可以从xml扩展视图,并以编程方式将其添加到容器布局中
View inflatedLayout= getLayoutInflater().inflate(R.layout.my_view, null, false);
container.addView(inflatedLayout);
my_view.xml
<com.skyfishjy.library.RippleBackground
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/content"
app:rb_color="#0099CC"
app:rb_radius="32dp"
app:rb_rippleAmount="4"
app:rb_duration="3000"
app:rb_scale="6">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerInParent="true"
android:id="@+id/centerImage"
android:src="@drawable/demoImage"/>
</com.skyfishjy.library.RippleBackground>
在
drawable
文件夹中创建ripple.xml
ripple.xml:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorFocusedHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
请尝试使用第三方来创建ripple。在
drawable
文件夹中创建ripple.xml
ripple.xml:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorFocusedHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
试着用第三方代替ripple