Drawable first = imageViewFirst.getDrawable();
Drawable second = imageViewSecond.getDrawable();
Drawable.ConstantState stateFirst = first.getConstantState();
Drawable.ConstantState stateSecond = second.getConstantState();
if(stateFirst.equals(stateSecond)) {
// ваш код
}
Drawable imageViewDrawable = imageViewFirst.getDrawable();
Drawable.ConstantState imageViewDrawableState =imageViewDrawable.getConstantState();
Drawable fromResourcesDrawable = getResources().getDrawable(R.drawable.my_drawable);// ваш ресурс
Drawable.ConstantState fromResourcesState = fromResourcesDrawable.getConstantState();
if(imageViewDrawable.equals(fromResourcesState)) {
// ваш код
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bgforobject"
tools:context="samsung.ru.spacex.InfRocket">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="30%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="3%"
app:layout_marginLeftPercent="28.9%"
android:background="@drawable/rocket_name1"
android:id="@+id/imageViewNameRocket_1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="10%"
app:layout_heightPercent="70%"
app:layout_marginBottomPercent="10.8%"
app:layout_marginLeftPercent="28.9%"
android:background="@drawable/rocket_2"
android:id="@+id/imageViewInfRocket"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="20%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="20%"
app:layout_marginRightPercent="28.9%"
android:background="@drawable/speed"
android:id="@+id/imageViewSpeed"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="25%"
app:layout_heightPercent="20%"
app:layout_marginTopPercent="14.5%"
app:layout_marginRightPercent="10%"
android:background="@drawable/counts3"
android:id="@+id/imageViewCounts3"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="24%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="32%"
app:layout_marginRightPercent="28.9%"
android:background="@drawable/strength"
android:id="@+id/imageViewStrength"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="25%"
app:layout_heightPercent="20%"
app:layout_marginTopPercent="26.5%"
app:layout_marginRightPercent="10%"
android:background="@drawable/counts2"
android:id="@+id/imageViewCounts2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="24%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="44%"
app:layout_marginRightPercent="28.9%"
android:background="@drawable/mobility"
android:id="@+id/imageViewMobility"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="25%"
app:layout_heightPercent="20%"
app:layout_marginTopPercent="38.5%"
app:layout_marginRightPercent="10%"
android:background="@drawable/counts2"
android:id="@+id/imageViewCounts22"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="24%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="56%"
app:layout_marginRightPercent="28.9%"
android:background="@drawable/capacity"
android:id="@+id/imageViewCapacity"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="25%"
app:layout_heightPercent="20%"
app:layout_marginTopPercent="50.5%"
app:layout_marginRightPercent="10%"
android:background="@drawable/counts4"
android:id="@+id/imageViewCounts4"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_widthPercent="16%"
app:layout_heightPercent="9%"
app:layout_marginRightPercent="17%"
app:layout_marginBottomPercent="19%"
android:id="@+id/imageButtonBuyRocket"
android:background="@drawable/buy"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
</android.support.percent.PercentRelativeLayout>