Note that there are some explanatory texts on larger screens.

plurals
  1. POListView - Highlight sub layout of item
    text
    copied!<p>I have been searching for the straight answer to this question for quite some time now. What I want to know is how to implement a custom highlight on a ListView that will only hightlight (over top, preferably) a sub layout of the ListView item (in this case, I'm looking to highlight the RelativeLayout of the item).</p> <p>Here is a screen shot of what I've got going on:<a href="http://imgur.com/ocnhQIt.png" rel="nofollow">Fail</a></p> <p>Here is the code for list_item.xml:</p> <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="72dp" android:clickable="false"&gt; &lt;RelativeLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:background="@drawable/card_layout"&gt; &lt;LinearLayout android:id="@+id/linearLayout_thumbnail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_vertical"&gt; &lt;ImageView android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/imageView_thumbnail"/&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="wrap_content" android:layout_height="50dp" android:orientation="vertical" android:layout_toRightOf="@+id/linearLayout_thumbnail" android:gravity="center_vertical"&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView_title" android:paddingLeft="5dp" android:textSize="18dp" android:text="SOME TEXT" /&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView_subtitle" android:paddingLeft="5dp" android:textSize="12dp" /&gt; &lt;/LinearLayout&gt; &lt;TextView android:id="@+id/textView_other" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="12dp" android:layout_alignParentRight="true" android:layout_centerVertical="true"/&gt; &lt;/RelativeLayout&gt; &lt;/FrameLayout&gt; </code></pre> <p>And the code for the ListView for that picture:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#e5e5e5"&gt; &lt;ListView android:id="@+id/listView_something" android:layout_width="wrap_content" android:layout_height="match_parent" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:listSelector="@drawable/list_item_selector" android:drawSelectorOnTop="true"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>The code for list_item_selector.xml:</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:drawable="@color/list_item_selected" android:state_pressed="true"/&gt; &lt;item android:drawable="@android:color/transparent" android:state_focused="true"/&gt; &lt;item android:drawable="@android:color/transparent"/&gt; &lt;/selector&gt; </code></pre> <p>Here's the file for the card_layout.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item&gt; &lt;shape android:shape="rectangle" android:dither="true"&gt; &lt;corners android:radius="2dp"/&gt; &lt;solid android:color="#ccc" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;item android:bottom="2dp"&gt; &lt;shape android:shape="rectangle" android:dither="true"&gt; &lt;corners android:radius="2dp" /&gt; &lt;solid android:color="@android:color/white" /&gt; &lt;padding android:bottom="7dp" android:left="5dp" android:right="5dp" android:top="5dp" /&gt; &lt;/shape&gt; &lt;/item&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:drawable="@color/list_item_selected" android:state_pressed="true"/&gt; &lt;item android:drawable="@android:color/transparent" android:state_focused="true"/&gt; &lt;item android:drawable="@android:color/transparent"/&gt; &lt;/selector&gt; </code></pre> <p></p> <p>Here's what happens when I switch the RelativeLayout's background to the selector that the ListView is using, and change the ListView so that it's selector is transparent: <a href="http://i.imgur.com/cdJOV37.png" rel="nofollow">Sort of working</a></p> <p>So for whatever reason, the card_layout.xml file isn't allowed to have the two items before the selector information and everything goes weird. Can anyone tell me how this is properly implemented? <a href="http://i.imgur.com/DgL9WGb.png" rel="nofollow">Like Google Play Music</a> (This might not be the best example because it looks like a GridView or something along those lines)</p> <p>Do I have to implement a GridView to display this list?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload