我不知道该怎么说
我在CoordinatorLayout中有一个ViewPager的xml文件,

在另一个xml布局(片段布局)中,我有ImageView,
我将片段布局充气起来并显示在viewpager中,

问题在这里:

当我更改(甚至设置)ViewPager(或CoordinatorLayout)背景颜色时,
颜色对我的图片有影响(好像图片在ViewPager / CoordinatorLayout下)

如何禁用此效果?
感谢您的关注

这是屏幕截图:
android - viewPager背景颜色对我的图像的影响-LMLPHP

您会看到图像变绿,但是它应该在顶部并保存为原始mod

这是我的代码:

fragment_pager

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_horizontal_margin"
>


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ImageView
        android:id="@+id/section_img"
        android:layout_width="192dp"
        android:layout_height="192dp"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:alpha="0.30"
        android:background="@drawable/fab_shadow"
        android:scaleType="fitCenter" />


</FrameLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="@dimen/activity_horizontal_margin">

    <TextView
        android:id="@+id/section_label"
        style="@style/TextAppearance.AppCompat.Headline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        tools:text="Page One" />

    <TextView
        style="@style/TextAppearance.AppCompat.Body1"
        android:id="@+id/describe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/activity_horizontal_margin"
        android:alpha="0.7"
        android:gravity="center"
        android:text="Add a long description here about your app's
        important feature."
        android:textColor="@android:color/white" />


</LinearLayout>

</FrameLayout>


activity_pager

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5fccff"
>


<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="?attr/actionBarSize"

    />


<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_gravity="bottom"
    android:layout_marginBottom="?attr/actionBarSize"
    android:alpha="0.12"
    android:background="@android:color/white" />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_gravity="bottom"
    android:paddingEnd="@dimen/activity_horizontal_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingStart="@dimen/activity_horizontal_margin">


    <Button
        android:id="@+id/intro_btn_skip"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start|center"
        android:text="Skip"
        android:textColor="@android:color/white" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/intro_indicator_0"
            android:layout_width="8dp"
            android:layout_height="8dp"
            android:layout_marginEnd="@dimen/activity_margin_half"
            android:layout_marginRight="@dimen/activity_margin_half"
            android:background="@drawable/in" />

        <ImageView
            android:id="@+id/intro_indicator_1"
            android:layout_width="8dp"
            android:layout_height="8dp"
            android:layout_marginEnd="@dimen/activity_margin_half"
            android:layout_marginRight="@dimen/activity_margin_half"
            android:background="@drawable/out" />

        <ImageView
            android:id="@+id/intro_indicator_2"
            style="@style/Widget.AppCompat.Button.Borderless"
            android:layout_width="8dp"
            android:layout_height="8dp"
            android:background="@drawable/out" />

    </LinearLayout>


    <Button
        android:id="@+id/intro_btn_finish"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|center"
        android:text="Finish"
        android:textColor="@android:color/white"
        android:visibility="gone" />

    <ImageButton
        android:id="@+id/intro_btn_next"
        style="@style/Widget.AppCompat.Button.Borderless"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|center"
        android:padding="@dimen/activity_horizontal_margin"
        android:src="@drawable/ic_action_add"
        android:tint="@android:color/white" />


</FrameLayout>


</android.support.design.widget.CoordinatorLayout>


我在哪里设置颜色:

PagerActivity

    ...
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        getWindow().setStatusBarColor(ContextCompat.getColor(this,
        R.color.black_trans80));
    }

    setContentView(R.layout.activity_pager);


    // Create the adapter that will return a fragment for each of the
     three
    // primary sections of the activity.
    mSectionsPagerAdapter = new
    SectionsPagerAdapter(getSupportFragmentManager());

    mNextBtn = (ImageButton) findViewById(R.id.intro_btn_next);

    mSkipBtn = (Button) findViewById(R.id.intro_btn_skip);
    mFinishBtn = (Button) findViewById(R.id.intro_btn_finish);

    zero = (ImageView) findViewById(R.id.intro_indicator_0);
    one = (ImageView) findViewById(R.id.intro_indicator_1);
    two = (ImageView) findViewById(R.id.intro_indicator_2);



    mCoordinator = (CoordinatorLayout) findViewById(R.id.main_content);


    indicators = new ImageView[]{zero, one, two};

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setPageTransformer(false, new IntroPageTransformer());

    mViewPager.setCurrentItem(page);
    updateIndicators(page);

    final int color1 = ContextCompat.getColor(this, R.color.cyan);
    final int color2 = ContextCompat.getColor(this, R.color.orange);
    final int color3 = ContextCompat.getColor(this, R.color.green);

    final int[] colorList = new int[]{color1, color2, color3};

    final ArgbEvaluator evaluator = new ArgbEvaluator();

    mViewPager.addOnPageChangeListener(new
    ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset,
        int positionOffsetPixels) {

            /*
            color update
             */
            int colorUpdate = (Integer)
            evaluator.evaluate(positionOffset, colorList[position],
            colorList[position == 2 ? position : position + 1]);
            mCoordinator.setBackgroundColor(colorUpdate);

        }

        @Override
        public void onPageSelected(int position) {

            page = position;

            updateIndicators(page);

            switch (position) {
                case 0:
                    mCoordinator.setBackgroundColor(color1);
                    break;
                case 1:
                    mCoordinator.setBackgroundColor(color2);
                    break;
                case 2:
                    mCoordinator.setBackgroundColor(color3);
                    break;
            }
            ...

最佳答案

经过一番讨价还价终于找到了一个奇怪的解决方案:
图像的setAlpha(1.0f)可以解决!!!
(这很糟糕,因为它仅适用于API 11及更高版本)
这么奇怪...

10-07 19:37
查看更多