title: How to avoid total view-hierarchy re-layout when using EditText?
body: <h2>Background</h2>
  
  <p>I have a rather complex layout being shown to the user in an activity.</p>
  
  <p>One of the views is an EditText.</p>
  
  <p>Since I had to make one of the views stay behind the soft-keyboard, yet the rest above it, I had to listen to view-layout changes (written about it <a href="https://stackoverflow.com/q/34851155/878126"><strong>here</strong></a>).</p>
  
  <h2>The problem</h2>
  
  <p>I've noticed that whenever the EditText has focus and shows its caret, the entire view-hierarchy gets re-layout. </p>
  
  <p>You can see it by either looking at the log of the listener I've created, or by enabling  "show surface updates" via the developers settings.</p>
  
  <p>This causes bad performance on some devices, especially if the layout of the activity is complex or have fragments that have complex layouts.</p>
  
  <h2>The code</h2>
  
  <p>I'm not going to show the original code, but there is a simple way to reproduce the issue:</p>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.example.user.myapplication.MainActivity"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="just some text"/&gt;
  
          &lt;EditText
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:inputType="phone"
              android:text="write here"
              android:textSize="18dp"/&gt;
  
  
          &lt;TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="just some text 2"/&gt;
      &lt;/LinearLayout&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          findViewById(android.R.id.content).getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
  
              @Override
              public boolean onPreDraw() {
                  Log.d("AppLog", "onPreDraw");
                  return true;
              }
          });
      }
  }
  </code></pre>
  
  <h2>What I've tried</h2>
  
  <p>When disabling the caret (using "cursorVisible", which for some reason is called a "cursor" instead) , I can see that the problem doesn't exist.</p>
  
  <p>I've tried to find an alternative to the built-in caret behavior, but I can't find. Only thing I've found is <a href="https://stackoverflow.com/questions/31388810/android-edittext-stop-cursor-blinking-want-a-solid-cursor"><strong>this post</strong></a>, but it seems to make it static and I'm not sure as to how well it performs (performance and compatibility vs normal caret).</p>
  
  <p>I've tried to set the size of the EditText forcefully, so that it won't need to cause invalidation of the layout that contains it. It didn't work.</p>
  
  <p>I've also noticed that on the original app, the logs can (for some reason) continue being written even when the app goes to the background.</p>
  
  <p>I've reported about this issue (including sample and video) <a href="https://code.google.com/p/android/issues/detail?id=200022" rel="nofollow noreferrer"><strong>here</strong></a>, hoping that Google will show what's wrong or a fix for this.</p>
  
  <h2>The question</h2>
  
  <p>Is there a way to avoid the re-layout of the entire view hierarchy ? A way that will still let the EditText have the same look&amp;feel of normal EditText?</p>
  
  <p>Maybe a way to customize how the EditText behaves with the caret?</p>