Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Created May 13, 2016 21:08
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save udacityandroid/e9399aa9b3ffb7690d15b4b7fbe148db to your computer and use it in GitHub Desktop.
Save udacityandroid/e9399aa9b3ffb7690d15b4b7fbe148db to your computer and use it in GitHub Desktop.
Miwok App: Miwok app: List Item Views with pressed states
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for a single list item -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:background="@color/tan_background"
android:orientation="horizontal">
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height" />
<LinearLayout
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="@dimen/list_item_height"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/image"
android:orientation="vertical"
android:paddingLeft="16dp">
<TextView
android:id="@+id/miwok_text_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/white"
android:textStyle="bold"
tools:text="lutti" />
<TextView
android:id="@+id/default_text_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/white"
tools:text="one" />
</LinearLayout>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:src="@drawable/ic_play_arrow" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"/>
</RelativeLayout>
@ashwanth1109
Copy link

@sachinwork91
Using View with match_parent for width and height and selectableItemBackground works in this case because the ViewGroup is RelativeLayout.
In RelativeLayout, we can superimpose views on top of each other. So what we are doing in this case is creating a selectable view that
ripples on touch and superimposing it on the entire list item (because of match_parent width and height).
In activity_main, the ViewGroup is a LinearLayout which means that selectable view that you create cannot be superimposed on the category item. I hope this answer brings some clarity to your confusion.

@benqgit
Copy link

benqgit commented Feb 26, 2018

It's done ;)

@amy6
Copy link

amy6 commented Feb 27, 2018

🆘
Option 1 is not working for me and Option 2 is only partly working 😕 I can get the ripple effect only when I click on the imageView in the list row but not on the text part of the row. Anyone ever faced this weird issue ❓

@NoorEldali
Copy link

yaaaaay I finished the whole course wow that was a journey 😃
good luck in your future courses everyone

@NoorEldali
Copy link

@amy6 can you please provide us with your Word_list.xml code

@Nikoloutsos
Copy link

What a beautiful course was that! It was really fascinating.

@usamas2
Copy link

usamas2 commented Mar 17, 2018

I should give myself a present that I finish the course 👍 :)
really it was great journey, thank you very much

@shirimaG
Copy link

I really Appreciate the course content, it touches all important angels a beginner like me should know.
Thank you so much, great work to Udacity instructors team.

@badrddinb
Copy link

thanks

@MasterSami1985
Copy link

thank you for all

@sherifhisham
Copy link

sweet add

@vicrobot
Copy link

Only option 2 is working and i don't know why the first one isn't woring.

@doilio
Copy link

doilio commented Apr 15, 2018

Done... Sweet 😋

@hkintu
Copy link

hkintu commented Jun 12, 2018

I have enjoyed this one 👍 :>)

@dionsaputra
Copy link

this is not work for me

@mhd73383
Copy link

mhd73383 commented Jul 8, 2018

do we need to make the parent relativelayout to be horizontal oriented?
i thought is the orientation is just for linearlayout

@soft2004
Copy link

Done 💃

@tooptooptoop
Copy link

done

@KobusVorster
Copy link

Done done done

@kevalsanghani
Copy link

@sachinwork91
Using View with match_parent for width and height and selectableItemBackground works in this case because the ViewGroup is RelativeLayout.
In RelativeLayout, we can superimpose views on top of each other. So what we are doing in this case is creating a selectable view that
ripples on touch and superimposing it on the entire list item (because of match_parent width and height).
In activity_main, the ViewGroup is a LinearLayout which means that selectable view that you create cannot be superimposed on the category item. I hope this answer brings some clarity to your confusion.

Hey,
Shouldn't the superimposed view 'View' create a big ripple for entire parent that is the the RelativeLayout, not just the individual list items.

@kevalsanghani
Copy link

Can someone explain why android:drawSelectorOnTop="true" only works for word_list.XML and not on other XMLs?

@LuizPelegrini
Copy link

LuizPelegrini commented Sep 29, 2018

@sachinwork91
Using View with match_parent for width and height and selectableItemBackground works in this case because the ViewGroup is RelativeLayout.
In RelativeLayout, we can superimpose views on top of each other. So what we are doing in this case is creating a selectable view that
ripples on touch and superimposing it on the entire list item (because of match_parent width and height).
In activity_main, the ViewGroup is a LinearLayout which means that selectable view that you create cannot be superimposed on the category item. I hope this answer brings some clarity to your confusion.

Hey,
Shouldn't the superimposed view 'View' create a big ripple for entire parent that is the the RelativeLayout, not just the individual list items.

As you are handling with the item.layout only, be aware you are superimposed view 'View' for the item itself, not the whole screen

@LuizPelegrini
Copy link

option 1 didn't work for me either. Option 2 is the way to go

@kwonines
Copy link

Option 1 doesn't work for me also. It seems like that is a problem with lots of people. Switched to option 2 and it worked perfectly.

Copy link

ghost commented Jul 3, 2019

@sachinwork91
Using View with match_parent for width and height and selectableItemBackground works in this case because the ViewGroup is RelativeLayout.
In RelativeLayout, we can superimpose views on top of each other. So what we are doing in this case is creating a selectable view that
ripples on touch and superimposing it on the entire list item (because of match_parent width and height).
In activity_main, the ViewGroup is a LinearLayout which means that selectable view that you create cannot be superimposed on the category item. I hope this answer brings some clarity to your confusion.

thanks a lot i had the same problem

@AJM95
Copy link

AJM95 commented Aug 16, 2020

2020 I was here. pheeeww. This was a very long lesson guys. Phewww

@Abdelhaq-Bannar
Copy link

2021 ^^ i think i'm the last one hhh

@sarwarsateer
Copy link

anyone still here in 2021? lol
-Sarwar Sateer

Copy link

ghost commented Jun 25, 2021

Hey yo
Congrats on reaching this far everyone!!

@david-read-iii
Copy link

For those having issues with option 1, setting android:clickable="true" and android:focusable="true" helps in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment