2015-07-31 4 views
0

У меня есть вид Recycler, и их элементы должны быть доступны для просмотра. Я хочу, чтобы вся строка применяла эффект selectableItemBackground, но этого не происходит. Образ изображения занимает весь макет элемента в качестве фона. Почему селектируемый эффект не работает?Android - selectableItemBackground не отображается, когда нажимается на элемент

это мой XML-файл

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="?listPreferredItemHeightLarge" 
    android:background="?selectableItemBackground" 
    android:descendantFocusability="blocksDescendants"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true"> 
     <ImageView 
      android:id="@+id/background" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:contentDescription="@string/app_name" 
      android:src="@drawable/holder" 
      android:scaleType="centerCrop" 
      android:focusableInTouchMode="false"/> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/black" 
      android:alpha="0.3" /> 
    </FrameLayout> 

    <br.com.lexsis.pizzahut.presentation.widgets.CustomFontTextView 
     android:id="@+id/group_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:background="@android:color/transparent" 
     style="@style/TextView.EMenu" /> 

</RelativeLayout> 
+0

вам, вероятно, нужно использовать 'ColorFilter' для вашего' ImageView'. Взгляните сюда: http://stackoverflow.com/questions/4617898/how-can-i-give-imageview-click-effect-like-a-button-in-android –

+1

попробуйте добавить 'android: clickable =" true "' – qwertz

+1

где можно добавить clickable true? в родительском представлении RelativeLayout? – pablobaldez

ответ

-1

Вы можете добавить еще RelativeLayout и добавить к нему android:background="?attr/selectableItemBackground":

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="?listPreferredItemHeightLarge" 
    android:background="?selectableItemBackground" 
    android:descendantFocusability="blocksDescendants"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/selectableItemBackground"> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_centerHorizontal="true"> 

      <ImageView 
       android:id="@+id/background" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:contentDescription="@string/app_name" 
       android:src="@drawable/holder" 
       android:scaleType="centerCrop" 
       android:focusableInTouchMode="false"/> 

      <View 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/black" 
       android:alpha="0.3" /> 

     </FrameLayout> 

     <br.com.lexsis.pizzahut.presentation.widgets.CustomFontTextView 
      android:id="@+id/group_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:background="@android:color/transparent" 
      style="@style/TextView.EMenu" /> 

    </RelativeLayout> 

</RelativeLayout> 

Установка в корневой макет никогда не работал для меня.

Смежные вопросы