title: Android List View Row margins
body: <p>I was trying to create a simple list view that has some padding for each row.</p>
  
  <p>I did it in a really simple way, but I'm not sure if it is the right™ way to do it.</p>
  
  <p>This is what I got (code is below). As you can see when you tap a row, it is fully highlighted, and I want (if possible) to highlight only the view inside it (the one with the gray background, that is a TextView)</p>
  
  <p><img src="https://i.stack.imgur.com/vRZr6.png" alt="Example"></p>
  
  <p>this is the code for the Activity layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;ListView
          android:id="@android:id/list"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:divider="@null"
          android:dividerHeight="0dp" /&gt;
  
      &lt;TextView
          android:id="@android:id/empty"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/no_events" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and this is the code of the list item layout:</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="fill_parent"
      android:layout_height="match_parent"
      android:padding="10dp"&gt;
  
      &lt;TextView
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/text1"
          android:layout_width="fill_parent"
          android:layout_height="30dp"
          android:background="#ccc"
          android:text="placeholder" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Thanks for any reply!</p>
  
  <p>PS. I didn't upload the Activity, it is a simple ListActivity.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Resolved (thanks to Jorge Aguilar). The new code is this:</p>
  
  <p>List item:</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="fill_parent"
      android:layout_height="match_parent"
      android:padding="10dp"&gt;
  
      &lt;TextView
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/text1"
          android:layout_width="fill_parent"
          android:layout_height="30dp"
          android:background="@drawable/event_focused"
          android:text="placeholder" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Event focused file (which is in the drawable directory):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:state_pressed="true"
            android:drawable="@android:color/black" /&gt; &lt;!-- pressed --&gt;
      &lt;item android:state_focused="true"
            android:drawable="@android:color/darker_gray" /&gt; &lt;!-- focused --&gt;
      &lt;item android:state_hovered="true"
            android:drawable="@android:color/darker_gray" /&gt; &lt;!-- hovered --&gt;
      &lt;item android:drawable="@android:color/darker_gray" /&gt; &lt;!-- default --&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>I also added this:</p>
  
  <pre><code>android:listSelector="@android:color/transparent"
  </code></pre>
  
  <p>to my ListView :)</p>