So, I am using an ImageView
which overlay another ImageView.
By default the opacity or alpha value of that image is set to 0.2f or something. I want to change the opacity of the ImageView
to fully visible when I shift or put the cursor on that image. I am running this app in an Android studio TV emulator. I have read the documentation and other solutions, but it's not working.
Here is my layout file where I am using two ImageViews which overlay each other. In this case the second one is overlaying.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="350dp"
android:gravity="center">
<ImageView
android:id="@+id/premiumimageDescription"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/margin"
android:paddingRight="@dimen/margin"
android:scaleType="fitXY" />
<ImageView
android:focusable="true"
android:alpha="0.2"
android:id="@+id/trailerView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:src="@drawable/playbutton" />
</RelativeLayout>
Java file where I am using focuschange
method to change the opacity when cursor comes to that ImageView:
trailerView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
switch (v.getId())
{
case R.id.trailerView:
if(hasFocus)
{
trailerView.getDrawable().setAlpha(1);
trailerView.getBackground().setAlpha(255);
trailerView.setImageAlpha(1);
}
else
{
trailerView.getBackground().setAlpha(50);
trailerView.setImageAlpha((int) 0.2);
}
}
}
});