简体   繁体   English

android为白色时,为什么图像显示为浅灰色背景?

[英]Why images are displayed with light grey background, when it has white android?

在此处输入图片说明

When I am displaying image in ImageView using Glide , grey color is added in background.I have tried setting background color to transparent and even white in ImageView in my xml file.. But It is still not working..It is happening with every image I display in various activities. 当我使用GlideImageView显示图像时,在背景中添加了灰色。我尝试在xml文件的ImageView中将背景色设置为透明甚至白色。但是,它仍然不起作用。我参加各种活动。 Below is the screenshot of same image displayed in iPhone and Android Oreo. 以下是在iPhone和Android Oreo中显示的同一张图片的屏幕截图。 Below is my xml file: 以下是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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">

    <RelativeLayout
        android:id="@+id/second"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:background="#fff">

        <LinearLayout
            android:id="@+id/bklayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="28dp"
            android:paddingTop="8dp">

            <ImageView
             android:id="@+id/bkbutton"
             android:layout_width="35dp"
             android:layout_height="50dp"
             android:layout_marginLeft="8dp"
             android:layout_marginTop="8dp"
             app:srcCompat="@drawable/ic_keyboard_arrow_left_black_24dp"/>
         </LinearLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="wrap_content"
            android:layout_height="200dp"
            android:layout_centerInParent="true"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="35dp" />

        <LinearLayout
            android:id="@+id/indicator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/viewPager"
            android:layout_centerInParent="true"
            android:layout_gravity="center"
            android:gravity="center"
            android:orientation="horizontal">
         </LinearLayout>
    </RelativeLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/second"
        android:id="@+id/third"
        android:orientation="vertical">


        <View
            android:layout_width="match_parent"
            android:layout_height="8dp"
            android:layout_marginTop="2dp"
            android:background="@color/new_grey">
         </View>


        <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_marginRight="5dp"
           android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="0.9"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:orientation="vertical">

            <TextView
                android:id="@+id/product_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Product Name: "
                android:textColor="@android:color/black"
                android:textSize="18sp" />
                <com.example.unsan.grouponebuy.helpers.ExpandableTextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:maxLines="3"
                    android:id="@+id/desc"/>
             </LinearLayout>



            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"   
                android:orientation="vertical">

                <ImageView
                    android:layout_width="70dp"
                    android:layout_height="wrap_content"
                    android:id="@+id/fav"
                    android:padding="5dp"
                    app:srcCompat="@drawable/ic_favorite_grey_24dp" />

                <TextView
                    android:id="@+id/favtext"
                    android:layout_width="70dp"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:text="@string/favorite"
                    android:textColor="@color/grey_dark" />

          </LinearLayout>

        </LinearLayout>

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

        <TextView
            android:id="@+id/price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:textColor="@color/orange" />

        <TextView
            android:id="@+id/origprice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp" />
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/specification" />

            <TextView
                android:id="@+id/specification"
                android:layout_marginLeft="4dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="8dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/origin" />

            <TextView
                android:id="@+id/origin"
                android:layout_marginLeft="4dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />


        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/replacement_layout"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_check_box_green_24dp"/>
            <TextView
                android:layout_marginLeft="5dp"
                android:text="@string/replacement_policy"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:visibility="visible"
        android:orientation="vertical"
        android:id="@+id/prodCartLayout">
    <View

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




    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"

        android:orientation="horizontal">
        <ImageView

            android:layout_width="45dp"
            android:layout_height="50dp"
            android:layout_marginLeft="5dp"
            android:id="@+id/carticonbutton"
            android:src="@drawable/cart_bl" />


        <View
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"></View>

        <Button
            android:id="@+id/carttext"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingRight="5dp"
            android:paddingLeft="3dp"
            android:gravity="center_vertical"
            android:background="@color/red"
            android:textSize="16sp"
            android:text="@string/add_to_cart"
            android:textColor="@android:color/white" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:text="@string/outOfStock"
            android:layout_marginRight="8dp"
            android:layout_marginTop="12dp"
            android:textColor="@color/grey"
            android:id="@+id/soldout_text"
            android:visibility="gone"
            />
    </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/prodSelectedLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:visibility="gone">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal"
           >

            <ImageView
                android:layout_width="45dp"
                android:layout_height="50dp"
                android:layout_marginLeft="5dp"
                android:id="@+id/carticonbutton2"
                android:src="@drawable/cart_bl" />

            <View
                android:layout_width="0dp"
                android:layout_height="50dp"
                android:layout_weight="1"></View>

            <ImageView
                android:id="@+id/sub_quantity"
                android:layout_width="30dp"
                android:layout_height="50dp"
                android:layout_marginTop="4dp"
                android:src="@drawable/minus" />

            <TextView
                android:id="@+id/quantity"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="12dp"
                android:text="1"
                android:textSize="18sp" />

            <ImageView
                android:id="@+id/add_quantity"
                android:layout_width="30dp"
                android:layout_height="50dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="4dp"
                android:src="@drawable/add_on" />

        </LinearLayout>
    </LinearLayout>


</RelativeLayout>

My Java Code: 我的Java代码:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.product_detail);
        backButton = (ImageView) findViewById(R.id.bkbutton);
        cartImageButton = (ImageView) findViewById(R.id.carticonbutton);
        cartButton2 = (ImageView) findViewById(R.id.carticonbutton2);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        productNameText = (TextView) findViewById(R.id.product_name);
        originText = (TextView) findViewById(R.id.origin);
        specText = (TextView) findViewById(R.id.specification);
        favText = (TextView) findViewById(R.id.favtext);
        favImgView = (ImageView) findViewById(R.id.fav);
        priceText = (TextView) findViewById(R.id.price);
        soldOutText = (TextView) findViewById(R.id.soldout_text);
        quantityText = (TextView) findViewById(R.id.quantity);
        addButton = (ImageView) findViewById(R.id.add_quantity);
        subButton = (ImageView) findViewById(R.id.sub_quantity);
        originalPriceText = (TextView) findViewById(R.id.origprice);
        descriptionText = (ExpandableTextView) findViewById(R.id.desc);
        cartLinearLayout = (LinearLayout) findViewById(R.id.prodCartLayout);
        productSelectedLayout = (LinearLayout) findViewById(R.id.prodSelectedLayout);
        cartAddButton = (Button) findViewById(R.id.carttext);
        replacementLayout = (LinearLayout) findViewById(R.id.replacement_layout);
        listViews = new ArrayList<>();
        indicator = (LinearLayout) findViewById(R.id.indicator);
        globalProvider = GlobalProvider.getGlobalProviderInstance(getApplicationContext());
        buyNumView = new CircleBadgeView(this, cartButton2);
        buyNumView.setTextColor(Color.WHITE);
        buyNumView.setBackgroundColor(Color.RED);
        numBadge = new CircleBadgeView(this, cartImageButton);
        numBadge.setBackgroundColor(Color.RED);

        //cycleTextViewExpansion(descriptionText);
        // expandCollapsedByMaxLines(descriptionText);

        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent returnIntent = new Intent();
                returnIntent.putExtra("productupdated", product);
                setResult(Activity.RESULT_OK, returnIntent);
                finish();

            }
        });
        Intent intent = getIntent();
        product = (Product) intent.getSerializableExtra("product");


        List<String> imgList = product.getImageDisplay();
        if (Constants.getLanguage(this).equals("english")) {

            String origin = product.getOriginEn();


            productNameText.setText(product.getNameEn());
            originText.setText(origin);
            ;
            specText.setText(product.getSpecificationEn());
            if (product.getDescriptionEn() != null) {
                descriptionText.setText(product.getDescriptionEn());
            }
        } else {
            productNameText.setText(product.getNameCh());
            originText.setText(product.getOriginCh());
            specText.setText(product.getSpecificationCh());
            if (product.getDescriptionCh() != null) {
                descriptionText.setText(product.getDescriptionCh());
            }
        }

        boolean prodSelected = false;


        priceText.setText("$ " + product.getPrice());
        listViews.clear();


        indicator.removeAllViews();

        if (imgList.size() > 0)

        {
            for (int a = 0; a < imgList.size(); a++) {
                ViewGroup pager = (ViewGroup) getLayoutInflater().inflate(R.layout.viewpager_image, null);

                ImageView imageView = (ImageView) pager.findViewById(R.id.viewpagerimg);
               /* if (a == 0) {

                        imageView.setTransitionName(imgTransitionName);

                }
                */
                Glide.with(ProductDetailActivity.this).load(Constants.baseUrlStr + imgList.get(a)).override(500, 500).centerCrop().into(imageView);
                listViews.add(pager);


            }
            productDetailViewPagerAdapter = new ProductDetailViewPagerAdapter(listViews, this);
            viewPager.setAdapter(productDetailViewPagerAdapter);


            if (imgList.size() > 1) {
                for (int a = 0; a < imgList.size(); a++) {
                    if (a == 0) {
                        ImageView imgView = new ImageView(this);
                        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(15, 15);
                        imgView.setLayoutParams(lp);
                        imgView.setImageResource(R.drawable.selected_dot);
                        indicator.addView(imgView);


                    } else {
                        ImageView imgView = new ImageView(this);
                        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(15, 15);
                        lp.setMargins(20, 0, 0, 0);
                        imgView.setLayoutParams(lp);
                        imgView.setImageResource(R.drawable.default_dot);
                        // imgs.add(img);
                        indicator.addView(imgView);


                    }
                }
            } else {

                ImageView img = new ImageView(this);
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams
                        (15, 15);
                //lp.setMargins(5,0,0,0);
                img.setLayoutParams(lp);
                img.setImageResource(R.drawable.selected_dot);
                //imgs.add(img);
                indicator.addView(img);

            }
        }


        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener()

        {
            @Override
            public void onPageScrolled(int position, float positionOffset,
                                       int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                for (int i = 0; i < indicator.getChildCount(); i++) {
                    if (i == position) {
                        ((ImageView) indicator.getChildAt(i)).setImageResource(R.drawable.selected_dot);

                    } else {
                        ((ImageView) indicator.getChildAt(i)).setImageResource(R.drawable.default_dot);
                    }
                }


            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


    }

Below is theme of my app: 以下是我的应用程序的主题:

    <resources>

        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <item name="android:buttonStyle">@style/Button</item>


        </style>
        <style name="Button" parent="Widget.AppCompat.Button">
            <item name="android:textAllCaps">false</item>
        </style>

</resources>

在此处输入图片说明

Solution: 解:

Whichever parent layout you have placed your ImageView such as <LinearLayout> or <RelativeLayout> or <ConstraintLayout> , they all have a Default color code as #FAFAFA which is not exactly White and that one of the possible reason that 无论您放置了ImageView哪个父布局(例如<LinearLayout><RelativeLayout><ConstraintLayout> ,它们都具有默认颜色代码,例如#FAFAFA ,它并非完全是白色,并且可能是因为

White's color code as you might already know is #FFFFFF . 您可能已经知道White的颜色代码是#FFFFFF

So your answer lies in your layout, make the background color of your parent layout in which your ImageView resides as White #FFFFFF as shown below: 因此,答案就在您的布局中,将ImageView所在的父布局的背景色设置为白色 #FFFFFF ,如下所示:

    <LinearLayout
        android:id="@+id/bklayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="28dp"
        android:paddingTop="8dp"
        android:background="#FFFFFF">

        <ImageView
            android:id="@+id/bkbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"> 
   </LinearLayout>

UPDATE: Add the below line in your Glide as described Here 更新:按照下面的描述 Glide添加以下行

.dontTransform()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)

Try it, I hope this is the problem. 试试吧,希望这是问题所在。

终于找到了一个解决方案。这是Glide的问题https://github.com/bumptech/glide/issues/853使用DiskCacheStrategy.SOURCE和DecodeFormat.PREFER_ARGB_8888解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Galaxy Nexus上的Android Theme.Holo.Light在模拟器没有的时候有灰色背景 - Android Theme.Holo.Light on Galaxy Nexus has grey background when emulator does not 当背景颜色较浅时,Android通知图标颜色不会更改为灰色 - Android notification icon color is not changed to grey when background color is light 在白色背景上将白色图像显示为灰色:Android - Showing white image as grey on white background: Android android actionbar背景颜色是灰色而不是白色 - android actionbar background color is grey instead of white 在Android Image Asset Studio中删除灰色和白色方格背景 - Removing Grey and White Chequered background in Android Image Asset Studio Button 的边缘周围仍然有一条浅灰色线,而它的边缘具有相同的背景颜色 - the edge of a Button still has a light grey line around it while the edge of it has the same color of background ActionBar-Android中的条显示不正确的白色背景色 - ActionBar - incorrect white background color displayed of the bars in Android 如何创建带有白色背景,带有三角形箭头的灰色边框的布局-Android - How do I create a layout w/ a white background, grey border with a triangle arrow - Android 弹出窗口 window 处于活动状态时的灰色背景 - android - Grey-out background when popup window is active - android Android:为什么 CardView 边距不显示白色背景? - Android: why are CardView margins not showing white background?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM