2015-02-28 2 views
0

у меня есть экран в моем приложении, которое отображает некоторые категории для пользователей, чтобы выбрать, в GridView, следующим образом:Кнопка наслаивала на GridView не реагирует на события OnClick

enter image description here

Когда пользователь нажимает на категорию, появляется кнопка для пользователя, чтобы продолжить, следующим образом:

enter image description here

проблема заключается в том, что зеленая кнопка, которая появилась не реагирует на @OnClick (я использую ButterK nife для просмотров).

Вот макет XML:

activity_select_categories.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:id="@+id/g" 
android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/h" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginTop="22dp" 
     android:layout_marginBottom="22dp" 
     android:textSize="23sp" 
     android:text="CATEGORIES" /> 

     <GridView 
      android:id="@+id/gridView_selectCategoriesLayout_categories" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:columnWidth="90dp" 

      android:gravity="center" 
      android:horizontalSpacing="2dp" 
      android:numColumns="2" 
      android:stretchMode="columnWidth" 
      android:verticalSpacing="2dp" 
      /> 

</LinearLayout> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:visibility="gone" 
    android:clickable="true" 
    android:id="@+id/button_selectCategoriesLayout_continue" 
    android:alpha="0.8"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="#22c064"/> 

    <ImageView 
     android:layout_width="25dp" 
     android:layout_height="25dp" 
     android:layout_centerInParent="true" 
     android:background="#22c064" 
     android:src="@drawable/checkmark" 
     /> 



</RelativeLayout> 

Вот пользовательский вид сетки элемент:

grid_tem.xml

<com.entu.artapp.utils.SquareRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:id="@+id/root" 
android:gravity="center_horizontal"> 

<com.entu.artapp.utils.SquareImageView 
    android:id="@+id/gridItem_squareImageView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="centerCrop" 
    android:visibility="invisible" 
    /> 

<com.entu.artapp.utils.SquareImageView 
    android:id="@+id/gridItem_selectedColor" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#e85349" 
    android:visibility="invisible" 
    android:alpha="0.45" 
    android:scaleType="centerCrop"/> 

<com.entu.artapp.utils.SquareImageView 
    android:id="@+id/gridItem_constantGrey" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:alpha="0.45" 
    android:scaleType="centerCrop"/> 

<com.entu.artapp.utils.RectangularLinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:id="@+id/s" 
    android:orientation="vertical"> 

    <ImageView 
     android:id="@+id/gridItem_selectedCheckMark" 
     android:layout_width="20dp" 
     android:layout_height="20dp" 
     android:src="@drawable/checkmark" 
     android:visibility="invisible" 
     /> 

</com.entu.artapp.utils.RectangularLinearLayout> 

<ProgressBar 
    android:id="@+id/gridItem_progressBar" 
    style="?android:attr/progressBarStyleSmall" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:layout_centerInParent="true" 
    android:visibility="visible"/> 

<TextView 
    android:id="@+id/gridItem_textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:textColor="#ffffff" 
    android:textSize="15sp" 
    android:textAllCaps="true" 
    android:textStyle="bold" 
    android:visibility="invisible"/> 

А вот как я поставил OnClick для моей кнопки:

@OnClick(R.id.button_selectCategoriesLayout_continue) 
public void setContinueButton() { 
    ParseUser.getCurrentUser().put("followedCategories", categoriesSelectedList); 
    ParseUser.getCurrentUser().put("followedCategoriesNames", categoriesNamesSelectedList); 
    ParseUser.getCurrentUser().saveInBackground(); 
} 

Может кто-нибудь помочь мне в решении почему кнопка не реагирует на OnClick? ButterKnife.inject (this) был вызван.

Дополнительно: У меня есть альфа-анимация на кнопке. Хотя я звоню .setVisibility (VIEW.GONE), кнопка исчезает, но место, где кнопка/не может быть нажата, не может быть нажата. Я прочитал на аналогичных темах анимации и конфликтах VIEW.GONE, что это может быть ошибка, и предложил использовать .clearAnimation(). Но, если я назову это, альфа-анимация сбрасывается, и это испортит мой интерфейс.

Может ли кто-нибудь помочь мне решить любую из этих проблем?

Cheers!

EDIT # 1: код, где я анимированные кнопки:

@InjectView(R.id.button_selectCategoriesLayout_continue) 
RelativeLayout continueButton; 

categoriesGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { 

[...] 

if (categoriesNamesSelectedList.size() == 0) { 
         deselectedAnimation.setAnimationListener(new Animation.AnimationListener() { 
         @Override 
         public void onAnimationStart(Animation animation) { 

         } 

         @Override 
         public void onAnimationEnd(Animation animation) { 
          continueButton.setVisibility(View.GONE); 
         } 

         @Override 
         public void onAnimationRepeat(Animation animation) { 

         } 
        }); 
        continueButton.startAnimation(deselectedAnimation); 
       } 
} 
+0

Можете ли вы опубликовать код, в котором вы живите внешний вид и исчезновение кнопки? (Имейте в виду, что в вашем коде это не кнопка, которую можно нажать, но родитель кнопки, «RelativeLayout») –

+0

Да, я знаю, слушатель находится на макете. Но это все еще не работает. –

+0

Покажите нам код, в котором вы анимируете кнопку. –

ответ

2

Ваша кнопка внутри RelativeLayout крадет событие щелчка от макета. Вы должны удалить кнопку из RelativeLayout (так или иначе вы ее не используете) и установить фон RelativeLayout вместо кнопки.

+0

Спасибо большое! это сработало. Может быть, такие полезные люди, как вы. –