How to set opacity for an image but not for the text in a recyclerView (android)

0

I have a recyclerView to which I pass images and text, in the activity that feeds the recyclerView I am trying to establish opacity for the images but not for the text, however both are affected and it is not what I want. As an achievement that the text is not affected when you set the opacity to the image? '

Activity that feeds the recyclerView (in which I want to set the opacity only to the image)

<LinearLayout
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


    <ImageView
        android:id="@+id/idImagen"
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:layout_marginTop="10dp"
        android:src="@drawable/beers"
        android:alpha="0.5"/>


</LinearLayout>

<TextView
    android:id="@+id/idNombre"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="Nombre"
    android:textColor="@android:color/white"
    android:textSize="24sp"
    app:layout_constraintBottom_toBottomOf="@+id/frameLayout"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

'

Activity of the recyclerView

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


    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp">

    </android.support.v7.widget.RecyclerView>
</LinearLayout>

    
asked by Yop 07.03.2018 в 13:01
source

1 answer

0

You can do it in the following ways:

  • It is to create a bitmap type xml with the image that you want to put in the background and apply to it the property android:alpha , in this way you will not affect the opacity of secondary elements. Then in res/drawable :

    <?xml version="1.0" encoding="utf-8"?>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/tuImagen"
        android:alpha="0.4"/>
    
  • In case the opacity you want to apply it pragmatically, from java you can do the following:

    yourView.getBackground().setAlpha(120); 
    
  • I hope you get the tools.

        
    answered by 08.10.2018 в 05:45