-
-
Save udacityandroid/e9399aa9b3ffb7690d15b4b7fbe148db to your computer and use it in GitHub Desktop.
<?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> |
Done 💃
done
Done done done
@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.
Can someone explain why android:drawSelectorOnTop="true" only works for word_list.XML and not on other XMLs?
@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
option 1 didn't work for me either. Option 2 is the way to go
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.
@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
2020 I was here. pheeeww. This was a very long lesson guys. Phewww
2021 ^^ i think i'm the last one hhh
anyone still here in 2021? lol
-Sarwar Sateer
Hey yo
Congrats on reaching this far everyone!!
For those having issues with option 1, setting android:clickable="true"
and android:focusable="true"
helps in some cases.
do we need to make the parent relativelayout to be horizontal oriented?
i thought is the orientation is just for linearlayout