title: Android: How to avoid ImageView flashing when the screen is clicked?
body: <p>I have an <code>ImageView</code> on the screen that I've scaled. When I click on the screen, the image goes back to its original size, and then the scaled size, and then back again constantly. Any ideas on how to fix this? Or why this is happening?<BR>
  My code for the <code>ImageView's</code> fragment</p>
  
  <pre><code>public class LargeFragment extends Fragment {
      Button back;
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          final View view = inflater.inflate(R.layout.large,container,false);
          final ImageView p = (ImageView) view.findViewById(R.id.large);
          final SharedPreferences pref = getActivity().getSharedPreferences("high",0);
          p.setImageResource(getResources().getIdentifier(pref.getString("selectedPlayer","pink").concat("large"), "drawable",view.getContext().getPackageName()));
          view.post(new Runnable() {
              @Override
              public void run() {
                  p.requestLayout();
                  final int w = view.getWidth();
                  p.getLayoutParams().height = w; //scaling the image here
              }
          });
          back = (Button) view.findViewById(R.id.exit);
          back.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  LargeFragment.this.getActivity().finish();
              }
          });
          return view;
      }
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  }
  </code></pre>
  
  <p>XML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent" android:layout_height="match_parent"
      android:background="@drawable/bg2"&gt;
     &lt;ImageView
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:id="@+id/large"
         android:rotation="270"
         android:scaleType="fitCenter"
         android:layout_gravity="center_vertical"
        /&gt;
      &lt;Button
          android:text="Button"
          android:layout_width="wrap_content"
          android:layout_gravity="end"
          android:layout_height="35dp"
          android:id="@+id/exit" /&gt;
  &lt;/FrameLayout&gt;
  </code></pre>