pavelsiamak / alpha-movie

Android video player with alpha channel (chroma key) support
https://github.com/pavelsemak/alpha-movie
Apache License 2.0
145 stars 43 forks source link

java code new AlphaMovieView #2

Closed sam2099 closed 2 years ago

sam2099 commented 7 years ago

Thank you for AlphaMovie。

How can i java code to new a AlphaMovieView ?

ThomasXu18 commented 6 years ago

try this.

            XmlPullParser xpp  = getResources().getXml(R.xml.alpha_movie_view_xml);
            try {
                xpp.next();
                xpp.nextTag();
            } catch (Exception e) {
                e.printStackTrace();
            }
            AttributeSet attr = Xml.asAttributeSet(xpp);
            Log.i("attr count ",attr.getAttributeCount()+"");
            final AlphaMovieView alpha = new AlphaMovieView(this, attr);
            LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            params.gravity = Gravity.CENTER;
            alpha.setLayoutParams(params);
            alpha.setOpaque(false);

            frameLayout.addView(alpha);

and xml file like this image

and my xml file likes this

<?xml version="1.0" encoding="utf-8"?>
<com.alphamovie.lib.AlphaMovieView
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_gravity="center"
    custom:alphaColor="#00ff00"
    custom:accuracy="0.4" />