What I have done is on button click I have hidden the barcode scanner i.e used the ObjectAnimator for "Y" translation. At the same time, recyclerview which is below barcode scanner will also be translated in "Y" direction using ObjectAnimator. Animation works great only problem that when recylcerview is "Y" translated, then below it has some white space and I am not able to make it fill whole space available. Check below code which I have used.
//scannerLayout is barcode scanner and recycler view is list
int height1 = scannerLayout.getHeight();
ObjectAnimator objectAnimator = ofFloat(scannerLayout, "translationY", 0, -1 * (height1));
objectAnimator.setDuration(1000);
objectAnimator.start();
ObjectAnimator objectAnimator1 = ofFloat(recyclerView, "y", barcodeInputBoxHeight); //barcodeInputBoxHeight - is height of edittext which is shown between toolbar and recyalerview
objectAnimator1.setDuration(1000);
objectAnimator1.start();
objectAnimator1.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animator) {
}
#Override
public void onAnimationEnd(Animator animator) {
// here I am doing some other stuff
}
#Override
public void onAnimationCancel(Animator animator) {
}
#Override
public void onAnimationRepeat(Animator animator) {
}
});
I tried setting new layout params for recyclerview onAnimationEnd but it didn't work.
Check the below video for exact problem
Video
Below is layout xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_pos"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".modules.pos.POSActivity">
<FrameLayout
android:id="#+id/screenFrame"
android:layout_width="match_parent"
android:layout_height="200dp"
android:elevation="6dp">
<com.journeyapps.barcodescanner.DecoratedBarcodeView
android:id="#+id/barcode_scanner"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.journeyapps.barcodescanner.DecoratedBarcodeView>
<ImageButton
android:id="#+id/imageButtonFlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="15dp"
android:background="#drawable/button_border"
app:srcCompat="#drawable/ic_action_flash"/>
<ImageButton
android:id="#+id/imageButtonInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="5dp"
android:layout_marginTop="25dp"
android:background="#drawable/button_border"
android:visibility="gone"
app:srcCompat="#drawable/ic_action_input_barcode"/>
</FrameLayout>
<FrameLayout
android:id="#+id/rlInputBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#color/colorPrimary"
android:elevation="8dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="10dp"
android:visibility="visible">
<EditText
android:id="#+id/editTextSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:background="#drawable/round_corner"
android:ems="10"
android:hint="Search"
android:imeOptions="actionSearch"
android:inputType="number"
android:paddingBottom="5dp"
android:paddingEnd="30dp"
android:paddingLeft="10dp"
android:paddingRight="20dp"
android:paddingStart="10dp"
android:paddingTop="5dp"/>
<ImageView
android:id="#+id/imageViewCloseInputBox"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="end|center_vertical"
android:layout_marginEnd="60dp"
android:layout_marginRight="60dp"
android:src="#drawable/ic_action_close_input_box"/>
<ImageView
android:id="#+id/imageViewSwitchKeyboard"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="end|center_vertical"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/ic_action_keyboard"/>
</FrameLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/buttonCheckOut"
android:layout_below="#+id/screenFrame"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"/>
<Button
android:id="#+id/buttonCheckOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:elevation="6dp"
android:text="Checkout"
android:textColor="#ffffff"/>
Related
trying to make showing LinarLayout from GONE state to VISIBLE with "roll down" animation. On this Layout exist TextView. Seems to all work fine but, a TextView not shown after animation.
What I do wrong?
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/ll_info">
<TextView
android:id="#+id/bayer_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="#string/buyer_note"/>
<RelativeLayout
android:id="#+id/button_continue"
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:background="#drawable/button_register"
android:drawableEnd="#drawable/ic_arrow_forward_white_24dp">
<TextView
android:id="#+id/btn_cont_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Войти"
android:textColor="#android:color/white"
android:textSize="20sp"
android:fontFamily="fonts/SF-UI-Display-Regular.ttf"
android:layout_centerInParent="true" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView"
android:layout_centerVertical="true"
android:layout_alignParentEnd="false"
android:src="#drawable/ic_door"
android:layout_toRightOf="#+id/btn_cont_caption"
android:layout_marginLeft="10dp"
android:scaleType="fitCenter" />
</RelativeLayout>
</LinearLayout>
And animation code:
final LinearLayout ll_info = (LinearLayout)findViewById(R.id.ll_info);
class scaleAnimation extends Animation {
public LinearLayout ll;
public int newHeight;
public void scaleTopHeight(int height)
{
newHeight = height;
}
public void setLayout(LinearLayout layout) {
ll = layout;
}
}
final LinearLayout ll_info = (LinearLayout)findViewById(R.id.ll_info);
scaleAnimation h = new scaleAnimation() {
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
ll.getLayoutParams().height = interpolatedTime == 1
? LinearLayout.LayoutParams.WRAP_CONTENT
: (int)(newHeight * interpolatedTime);
ll.requestLayout();
}
};
h.setDuration(300);
h.setLayout(ll_info);
ll_info.setVisibility(View.VISIBLE);
ll_info.measure(View.MeasureSpec.makeMeasureSpec(((LinearLayout)ll_info.getParent()).getWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(((LinearLayout)ll_info.getParent()).getHeight(), View.MeasureSpec.AT_MOST));
h.scaleTopHeight(ll_info.getMeasuredHeight());
ll_info.getLayoutParams().height=1;
ll_info.startAnimation(h);
<RelativeLayout
android:id="#+id/button_continue"
android:layout_width="match_parent"
android:layout_height="54dp"
**android:layout_centerHorizontal="true"** /////
remove this
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:background="#drawable/button_register"
android:drawableEnd="#drawable/ic_arrow_forward_white_24dp">
<TextView
android:id="#+id/btn_cont_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Войти"
android:textColor="#android:color/white"
android:textSize="20sp"
android:fontFamily="fonts/SF-UI-Display-Regular.ttf"
android:layout_centerInParent="true" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView"
android:layout_centerVertical="true"
android:layout_alignParentEnd="false"
android:src="#drawable/ic_door"
android:layout_toRightOf="#+id/btn_cont_caption"
android:layout_marginLeft="10dp"
android:scaleType="fitCenter" />
</RelativeLayout>
i think this is your xml file issue ,your relativelayout in center_horizontal and all the childs are in center in parent.so textview hides over imageview. Try it and let me know.
I have three views 1)Toolbar 2)Edittext and Recyclerview. Now on click on edittext i want to animate the toolbar to the top(out of screen generally) up along with edittext and recyclerview .The animation works fine but the problems is that the recycler view is not taking the full height.The recycler view is moved to the top but also recyclerview is not taking the full height
XMl
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<include
android:id="#+id/tb_explore"
layout="#layout/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></include>
<LinearLayout
android:id="#+id/ll_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tb_explore"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:layout_marginTop="07dp"
android:focusable="false"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="#+id/et_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/imageView11"
android:layout_toStartOf="#+id/imageView11"
android:background="#android:color/transparent"
android:hint="Search by vendor name or keyword"
android:padding="10dp"
android:imeOptions="actionGo"
android:singleLine="true"
android:textSize="#dimen/regular" />
<TextView
android:id="#+id/tv_cancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="center"
android:text="Cancel"
android:visibility="gone" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_explore_search"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_below="#+id/ll_search"
android:layout_marginTop="10dp"
android:background="#efd3d3"
android:visibility="visible" />
Code
rlHeader.animate()
.translationY(-rlHeader.getHeight());
llSearch.animate()
.translationY(-rlHeader.getHeight())
.setListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
rvExplore.getLayoutParams().height = rvExplore.getHeight() + rlHeader.getHeight(); //here i am increasing the height but no use
rvExplore.animate().translationY(-rlHeader.getHeight());
}
#Override
public void onAnimationEnd(Animator animation) {
etSearch.requestFocus();
tvCancel.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationCancel(Animator animation) {
}
#Override
public void onAnimationRepeat(Animator animation) {
}
});
I have seen the questions in the stack over flow, even I tried,
Android Translate Animation like Swapping Two Views
But nothing worked for my scenario, I want to swap swap_above linear layout and swap_below linear layouts when click on swap image button. If possible I would like to apply animation for swap imagebutton also, when the views are being swapped.
Thank you,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/from"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="25dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/swap_above"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/from_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/from_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/seek_thumb_pressed"
android:drawablePadding="5dp"
android:text="BANGALORE"
android:textSize="20dp" />
<TextView
android:id="#+id/from_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=" (BLR)"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="0.5dp"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:background="#FFF" />
<View
android:layout_width="60dp"
android:layout_height="0dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/to"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="25dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/swap_below"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/to_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/to_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/seek_thumb_normal"
android:drawablePadding="5dp"
android:text="Hyderabad"
android:textSize="20dp" />
<TextView
android:id="#+id/to_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=" (HYD)"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="#+id/swap"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical|end"
android:background="?android:attr/selectableItemBackground"
android:src="#drawable/seek_thumb_disabled" />
</FrameLayout>
</LinearLayout>
First - set the below xml attributes for each target view's parent which may be blocking the animation :
android:clipChildren="false"
android:clipToPadding="false"
You need to set this attributes at 3 places in your case.
Read more about clipChildren & clipToPadding here -
http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipChildren
http://developer.android.com/reference/android/view/ViewGroup.html#attr_android:clipToPadding
If your minSDK >=12
Use this for swap animation :
findViewById(R.id.swap).setOnClickListener(new View.OnClickListener() {
boolean isAnimating;
#Override
public void onClick(View v) {
if(isAnimating)
return;
isAnimating=true;
View v1 = findViewById(R.id.swap_above);
View v2 = findViewById(R.id.swap_below);
float x1, y1, x2, y2;
x1 = getRelativeX(v1);//Use v1.getX() if v1 & v2 have same parent
y1 = getRelativeY(v1);//Use v1.getY() if v1 & v2 have same parent
x2 = getRelativeX(v2);//Use v2.getX() if v1 & v2 have same parent
y2 = getRelativeY(v2);//Use v2.getY() if v1 & v2 have same parent
float x_displacement = (x2-x1);
float y_displacement = (y2-y1);
v1.animate().xBy(x_displacement).yBy(y_displacement);
v2.animate().xBy(-x_displacement).yBy(-y_displacement);
long anim_duration = v1.animate().getDuration();
//Wait till animation is over to set isAnimating to false
//take 10 ms as buffer time to ensure proper functioning
//If you remove this timer & isAnimating variable, the animation will function improperly when user rapidly clicks on swap button
new CountDownTimer(anim_duration + 10, anim_duration + 10) {
#Override
public void onTick(long millisUntilFinished) {
}
#Override
public void onFinish() {
isAnimating=false;
}
}.start();
}
//returns x-pos relative to root layout
private float getRelativeX(View myView) {
if (myView.getParent() == myView.getRootView())
return myView.getX();
else
return myView.getX() + getRelativeX((View) myView.getParent());
}
//returns y-pos relative to root layout
private float getRelativeY(View myView) {
if (myView.getParent() == myView.getRootView())
return myView.getY();
else
return myView.getY() + getRelativeY((View) myView.getParent());
}
});
Read about View Property animator here -
http://developer.android.com/reference/android/view/ViewPropertyAnimator.html
http://developer.android.com/guide/topics/graphics/prop-animation.html
Also, you should try to minimize the number of views in your layout.
Read about layout optimization here -
http://developer.android.com/training/improving-layouts/optimizing-layout.html
I have created a recyclerview usin cardview and added button in each of the items of the recyclerview. I have already integrated the button click event . Now, when I click the button of one of the recyclerview item it responds normally and the button of other items responds too at the same time as if they are also clicked.what is the problem? how can it be solved?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="95dp"
android:orientation="horizontal"
android:weightSum="3">
<android.support.v7.widget.CardView
android:id="#+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:cardCornerRadius="1dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true">
<ImageView
android:id="#+id/icon_vendor1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="5dp"
android:layout_marginRight="10dp"
android:padding="0dp"
android:scaleType="fitXY"
android:src="#drawable/ic_direction" />
<TextView
android:id="#+id/vendorName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/icon_vendor1"
android:text="Kozzaja Infotech Pvt Ltd"
android:textSize="20sp" />
<RatingBar
android:id="#+id/rating"
style="#style/RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/vendorName1"
android:layout_marginTop="4dp"
android:layout_toEndOf="#+id/imageView2"
android:layout_toRightOf="#+id/icon_vendor1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/vendorName1"
android:layout_marginBottom="3dp"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageButton
android:id="#+id/button4"
android:layout_width="38dp"
android:layout_height="wrap_content"
android:background="#drawable/circle_button"
android:padding="10dp"
android:src="#drawable/ic_call_black_36dp" />
<ImageButton
android:id="#+id/button3"
android:layout_width="38dp"
android:layout_height="wrap_content"
android:background="#drawable/circle_button"
android:padding="20dp"
android:src="#drawable/ic_messenger_outline_black_36dp" />
<ImageButton
android:id="#+id/button2"
android:layout_width="38dp"
android:layout_height="match_parent"
android:background="#drawable/circle_button"
android:src="#drawable/ic_directions_black_24dp" />
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="38dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/layout"
android:background="#drawable/circle_button"
android:tag="off"
android:text="+"
android:textSize="30sp" />
<View
android:layout_width="11dp"
android:layout_height="38dp"
android:background="#ffffff" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
This is my adapter's code.
#Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.title.setText(workers.get(position).getName());
holder.rating.setRating(workers.get(position).getRatings());
Picasso.with(context).load(workers.get(position).getImageLogo()).fit().into(holder.imageView);
holder.plus.setTag("off");
holder.plus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
/// button click event
if (holder.plus.getTag().toString().equals("off")) {
holder.plus.setTag("on");
holder.plus.setText("-");
//show the options button using animation
holder.layout.startAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_to_right));
holder.layout.setVisibility(View.VISIBLE);
} else if (holder.plus.getTag().toString().equals("on")) {
holder.plus.setTag("off");
holder.plus.setText("+");
//hide the options button using animation
holder.layout.startAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_to_left));
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//disappear the button after 500ms
holder.layout.setVisibility(View.GONE);
}
}, 500);
}
}
});
}
I have a screen in my app which displays some categories for the users to select, in a GridView, as following:
When a user clicks on a category, a button appears for the user to continue, as following:
The problem is, that the green button that appeared does not respond to #OnClick (I am using ButterKnife for views).
Here is the Layout 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>
Here is the custom grid view element:
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"/>
And here is how I set the OnClick for my button:
#OnClick(R.id.button_selectCategoriesLayout_continue)
public void setContinueButton () {
ParseUser.getCurrentUser().put("followedCategories", categoriesSelectedList);
ParseUser.getCurrentUser().put("followedCategoriesNames", categoriesNamesSelectedList);
ParseUser.getCurrentUser().saveInBackground();
}
Can anyone help me in solving why does the button not respond to OnClick?
ButterKnife.inject(this) has been called.
Extra: I have an alpha animation on the button. Although I am calling .setVisibility(VIEW.GONE), the button disappears, but the place where the button is/was cannot be clicked. I have read on similar topics on animations and VIEW.GONE conflicts that it might be a bug, and suggested using .clearAnimation(). But, if i call that, the alpha animation resets, and it messes up my UI.
Can anyone help me solve any of these problems?
Cheers!
EDIT #1: The code where i animated the button:
#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);
}
}
Your button inside the RelativeLayout steals the click event from the layout. You should delete the Button from the RelativeLayout (as you anyway don't use it) and set the background of the RelativeLayout instead of the button.