animation button

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
tools:context=".class6.book_view">

<androidx.cardview.widget.CardView
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:cardElevation="2dp"
app:cardBackgroundColor="@color/primaryColor"
android:background="@color/white" />





<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/toolBar"
app:layout_constraintBottom_toBottomOf="parent"
/>


<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolBar"
app:layout_constraintVertical_bias="1.0"
tools:layout_editor_absoluteX="-53dp" />

<HorizontalScrollView
android:id="@+id/category"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@+id/toolBar"
android:layout_height="wrap_content"><LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:layout_margin="@dimen/_5sdp"
android:textColor="@color/textPrimaryColor"
android:textSize="@dimen/_14sdp"
android:padding="@dimen/_5sdp"
android:background="@color/white"
android:elevation="2sp"
/>

<TextView
android:id="@+id/nctbBooks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NCTB Books"
android:layout_margin="@dimen/_5sdp"
android:textColor="@color/textPrimaryColor"
android:textSize="@dimen/_14sdp"
android:padding="@dimen/_5sdp"
android:background="@color/white"
android:elevation="2sp"
/>

<TextView
android:id="@+id/guideBooks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Guide Books"
android:layout_margin="@dimen/_5sdp"
android:textColor="@color/textPrimaryColor"
android:textSize="@dimen/_14sdp"
android:padding="@dimen/_5sdp"
android:background="@color/white"
android:elevation="2sp"
/>

</LinearLayout></HorizontalScrollView>

<ImageView
android:id="@+id/btnGoneVisible"
android:layout_width="@dimen/_30sdp"
android:layout_height="@dimen/_30sdp"
app:layout_constraintEnd_toEndOf="parent"
android:padding="@dimen/_5sdp"
android:tag="SHOWING"
android:layout_margin="@dimen/_5sdp"
android:background="@drawable/circle_shap"
app:layout_constraintTop_toBottomOf="@id/toolBar"
android:src="@drawable/arrow_back" />







<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:layout_constraintStart_toStartOf="parent"
ads:layout_constraintEnd_toEndOf="parent"
ads:layout_constraintBottom_toBottomOf="parent"
ads:adSize="BANNER"
ads:adUnitId="@string/admob_banner_id" />
</androidx.constraintlayout.widget.ConstraintLayout>

package com.apdim3.usolve.class6;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.TextView;


import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;


import com.apdim3.usolve.R;


public class book_view extends AppCompatActivity {

FrameLayout frameLayout;
ImageView btnGoneVisible;
HorizontalScrollView category;
private TextView notes, nctbBooks, guideBooks;
private int selectedColor, defaultColor;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_view);

frameLayout = findViewById(R.id.frameLayout);
category = findViewById(R.id.category);
btnGoneVisible = findViewById(R.id.btnGoneVisible);
notes = findViewById(R.id.notes);
nctbBooks = findViewById(R.id.nctbBooks);
guideBooks = findViewById(R.id.guideBooks);



btnGoneVisible.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (category.getVisibility() == View.VISIBLE) {
hideWithAnimation(category);
btnGoneVisible.setImageResource(R.drawable.arrow_forward); // Update icon if needed
} else {
showWithAnimation(category);
btnGoneVisible.setImageResource(R.drawable.arrow_back); // Update icon if needed
}
}
});

selectedColor = ContextCompat.getColor(this, R.color.selectedColor);
defaultColor = ContextCompat.getColor(this, R.color.white);


// Load the default fragment

} //========================== End OnCreate ======================

//-------------------Button Selected --------------------------

private void resetButtonColors() {
notes.setBackgroundColor(defaultColor);
nctbBooks.setBackgroundColor(defaultColor);
guideBooks.setBackgroundColor(defaultColor);
}

private void loadFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.frameLayout, fragment);
transaction.commit();
}

//================== Animation Start =====================
private void hideWithAnimation(final View view) {
view.animate()
.alpha(0.0f)
.setDuration(400)
.withEndAction(new Runnable() {
@Override
public void run() {
view.setVisibility(View.GONE);
}
});
}

private void showWithAnimation(final View view) {
view.setAlpha(0.0f);
view.setVisibility(View.VISIBLE);
view.animate()
.alpha(1.0f)
.setDuration(400)
.setListener(null);
}
}





Post a Comment

Post a Comment (0)

Previous Post Next Post