moto x4中的ViewPager无法正常工作

时间:2018-12-27 11:07:04

标签: android android-viewpager

我正在使用viewpager来显示3个屏幕,例如入门屏幕。在所有手机上都可以正常工作,但在Moto X4中无法正常工作。这些是Moto X4的屏幕截图:

这是xml代码:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:orientation="vertical"
        android:visibility="visible"
        android:weightSum="1">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="0dip"
            android:layout_weight="0.7">

            <LinearLayout
                android:id="@+id/viewpager_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:orientation="vertical">

                <android.support.v4.view.ViewPager
                    android:id="@+id/login_slide_viewpager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
            </LinearLayout>

            <android.support.design.widget.TabLayout
                android:id="@+id/login_tablayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@id/viewpager_container"
                app:tabBackground="@drawable/login_dot_selector"
                app:tabGravity="center"
                app:tabIndicatorHeight="0dp"
                app:tabRippleColor="@null"
                app:tabPaddingStart="7dp"
                app:tabPaddingEnd="7dp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.3"
            android:orientation="vertical"
            >

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/warm_grey" />

            <LinearLayout
                android:id="@+id/login_container"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:visibility="visible"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/bt_fb_login"
                    android:layout_width="232dp"
                    android:layout_height="53dp"
                    android:background="@drawable/facebook_button_background"
                    android:gravity="center_vertical"
                    android:orientation="horizontal">

                    <com.sharesmile.share.views.MRTextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="@string/logn_with_fb"
                        android:textAllCaps="true"
                        android:textColor="@color/white_95"
                        android:textSize="12.5sp" />

                    <ImageView
                        android:layout_width="47dp"
                        android:layout_height="47dp"
                        android:src="@drawable/logo_fb" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/bt_google_login"
                    android:layout_width="232dp"
                    android:layout_height="53dp"
                    android:layout_marginTop="13dp"
                    android:background="@drawable/google_button_background"
                    android:gravity="center_vertical"
                    android:orientation="horizontal">

                    <com.sharesmile.share.views.MRTextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="@string/logn_with_google"
                        android:textAllCaps="true"
                        android:textColor="@color/white_95"
                        android:textSize="13.4sp" />

                    <ImageView
                        android:layout_width="47dp"
                        android:layout_height="47dp"
                        android:background="@drawable/login_google"
                        android:src="@drawable/google_icon"
                        />
                </LinearLayout>
            </LinearLayout>
            <RelativeLayout
                android:id="@+id/progress_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:gravity="center"
                android:visibility="gone">

                <ProgressBar
                    android:id="@+id/progress_bar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </RelativeLayout>
        </RelativeLayout>
    </LinearLayout>

Java代码:

public class LoginSliderAdapter extends PagerAdapter {

    public int slider_videos[] = {
            R.raw.v1,
            R.raw.v2,
            R.raw.v3
    };
    @BindView(R.id.iv_slider_image)
    VideoView sliderImage;
    @BindView(R.id.tv_slider_title)
    TextView sliderTitle;
    @BindView(R.id.tv_slider_description)
    TextView sliderDescription;
    Context context;
    LayoutInflater layoutInflater;

    public LoginSliderAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.login_slider, container, false);
        ButterKnife.bind(this, view);
        setVideoToVideoPlayer(position);
        sliderTitle.setText(context.getResources().getStringArray(R.array.login_tiles)[position]);
        sliderDescription.setText(context.getResources().getStringArray(R.array.login_desc)[position]);
        container.addView(view);
        return view;
    }

    private void setVideoToVideoPlayer(int position) {
        Uri uri = Uri.parse("android.resource://com.sharesmile.share/"
                + slider_videos[position]);
        sliderImage.setBackgroundColor(Color.TRANSPARENT);
        sliderImage.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
            }
        });
        sliderImage.setVideoURI(uri);
        sliderImage.requestFocus();
        sliderImage.setZOrderOnTop(true);
        sliderImage.start();
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((LinearLayout) object);
    }
}

那么这个问题是什么,无法弄清楚,永远不会这样。

0 个答案:

没有答案