Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 向以图形方式添加的视图添加涟漪效果_Android_Android Layout_Android View_Android Xml_Ripple - Fatal编程技术网

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