Bounce scrolling effect in RecycleView - android-recyclerview

I want to implement bounce animation effect on android recycleview.
how can I do that?
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

Replace RecyclerView with RecyclerViewBouncy.
Add dependency:
dependencies {
implementation 'com.chauthai.overscroll:overscroll-bouncy:0.1.0'
}
In layout:
<com.chauthai.overscroll.RecyclerViewBouncy .../>
You can only use LinearLayoutManager

Related

How to place an icon in the navigation bar section in navigation pages

all the pages my app is navigation page . I wanted to know how to put an icon on all pages and in the navigation bar section ?
I want to write the code once and apply it to all pages.
Because when I enter the nested pages, icon disappears!
Thanks in advance to those who help me!
You could add an icon to the toolbar in the Android app project.
The default layout for the toolbar in a new template Forms app is:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light" >
</android.support.v7.widget.Toolbar>
Add an icon to this:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light" >
<ImageView
android:src="#drawable/star_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.Toolbar>
Updated:
Set id for the imageview in Toolbar.
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light" >
<ImageView
android:id="#+id/imageView1"
android:src="#drawable/star_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.Toolbar>
Add the code in MainActivity after LoadApplication(new App());.
var imageview = FindViewById<ImageView>(Resource.Id.imageView1);
imageview.Click += delegate
{
Console.WriteLine("start clicked!");
};
How can I enter HorizontalOptions="End" in the Toolbaritem.xml? I want to go to the right side of the page!
Add the code below in ImageView.
android:layout_gravity="end"
Screenshot:
Just use in your page:
<ContentPage
NavigationPage.HasNavigationBar="True"
NavigationPage.HasBackButton="False">
<NavigationPage.TitleView>
<Image />
</NavigationPage.TitleView>
YOUR VIEW
</ContentPage>

FloatingActionButton doesn't show icon inside of?

I have tried to use FAB button for add new somethings in my android application, but FAB have not showed its source icon. can you help me how i resolve it?
this is my main_activity.xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:id="#+id/main_container">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frg_holder"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:elevation="6dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_add"/>
</RelativeLayout>
and this is a ic_add.xml create icon inside of fAB:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
and this is gradle :
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'com.google.android.material:material:1.3.0-alpha03'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.github.samanzamani.persiandate:PersianDate:0.8'
implementation 'com.android.support:support-v4:29.1.0'
implementation 'com.android.support:design:29.0.0'
}

Xamarin XAML Spinner Styling Issue

I have a Spinner I'm trying to give a transparent background. Then on Load it can have a white background. However, no matter what background I give it's always white! Any help is appreciated.
<Spinner
android:id="#+id/fertilizer1_amount_unit"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:background="#00FF0000"
local:MvxDropDownItemTemplate="#layout/spinneritemdropdown"
local:MvxBind="SelectedItem ChemigationItem.Fertilizers[0].Unit;Enabled ChemigationItem.IsNew" />
SpinnerItemDropDown XAML:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:background="#color/white"
android:textColor="#color/text_gray"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:ellipsize="marquee"
local:MvxBind="Text Caption" />
This is what it looks like:
Thanks,
The reason for that is your CheckedTextView's background property:
android:background="#color/white"
Should actually be something like this:
android:background="#android:color/transparent"

Android: Animating FAB to top of dialog like SnackBar

I am showing a fab button on bottom of CoordinatorLayout. On top of that FAB, I want to show a dialog(animating it from bottom) and animate FAB to top of same dialog and make it work like close button for the dialog.
I know if we use CoordinatorLayout with FAB, SnackBar behave with same kind of animation but I want the same animation for dialog enter and exit too.
Is there any way I can achieve the same animation?
To show your snackbar
public static void showSnackBar(#NonNull View view, #NonNull CharSequence text,
#Snackbar.Duration int duration) {
Snackbar snack = Snackbar.make(view, text, duration);
TextView snackTextView = (TextView) snack.getView().findViewById(android.support.design.R.id.snackbar_text);
snackTextView.setMaxLines(5);
snack.show();
}
Here view is your reference to coordinator layout
In your xml place your fab button like this
<android.support.design.widget.CoordinatorLayout 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/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/stream_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/stream_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
<ProgressBar
android:id="#+id/groupLoadingView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/postButton"
android:layout_width="58dp"
android:layout_height="58dp"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:scaleType="center"
android:src="#drawable/chat_newpost_button_selector"
app:backgroundTint="#color/light_blue_color"
app:borderWidth="0dp"
app:elevation="6dp"
app:layout_anchor="#+id/stream_recyclerview"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>

Getting null pointer exception on clicking spinner

I am trying to display language and context in two different spinners. Here is the code
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
context = getContext();
rootView = inflater.inflate(R.layout.language_fragment, container,false);
dbRepo = DBRepo.getInstance(context);
getDialog().setTitle(Html.fromHtml("<font size='10' color='#9B9B9B'>Configuration Settings</font>"));
//language spinner
Spinner languageSpinner = (Spinner)rootView.findViewById(R.id.language_spinner);
List<String>languagelist;
languagelist = dbRepo.getLanguages(HomeFragment.projectGUID);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, languagelist);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
languageSpinner.setAdapter(adapter);
//context spinner
Spinner contextSpinner = (Spinner)rootView.findViewById(R.id.context_spinner);
List<String>contextlist;
contextlist = dbRepo.getContext(HomeFragment.projectGUID);
ArrayAdapter<String> adapterC = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, contextlist);
adapterC.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
contextSpinner.setAdapter(adapterC);
firstTym = true;
contextSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
languageSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
return rootView;
}
public class MyOnItemSelectedListener implements OnItemSelectedListener {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
String selectedItem = parent.getItemAtPosition(pos).toString();
if(firstTym)
{
//do nothing
}
else {
//check which spinner triggered the listener
switch (parent.getId()) {
//language spinner
case R.id.language_spinner:
Toast.makeText(parent.getContext(), "Language you selected is " + selectedItem, Toast.LENGTH_LONG).show();
dbRepo.updateDetails(selectedItem,null);
break;
//context spinner
case R.id.context_spinner:
Toast.makeText(parent.getContext(), "Context you selected is " + selectedItem, Toast.LENGTH_LONG).show();
dbRepo.updateDetails(null,selectedItem);
break;
}
}
firstTym = false;
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
}
This is the code where I have two spinners , context spinner works fine but when I click on language spinner, It's throwing null pointer exception
here is my xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="30dp"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:text="Select Language"
android:id="#+id/lang_txt"
android:gravity="center"
android:textSize="#dimen/abc_text_size_medium_material"
android:layout_margin="20dp"
android:layout_alignParentStart="true"/>
<Spinner
android:id="#+id/language_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:layout_toRightOf="#+id/lang_txt"
/>
</RelativeLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="30dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:text="Select Context"
android:id="#+id/con_txt"
android:layout_alignParentStart="true"
android:gravity="center"
android:textSize="#dimen/abc_text_size_medium_material"
android:layout_margin="20dp" />
<Spinner
android:id="#+id/context_spinner"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/con_txt"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</LinearLayout>
Can anyone suggest anything, what's wrong with the language spinner?
Here is the stack trace
12-18 10:58:09.084 22744-22744/com.example.mediaapp.prototypingcanvas E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.mediaapp.prototypingcanvas, PID: 22744
java.lang.NullPointerException
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:415)
at android.support.v7.widget.AppCompatSpinner$DropDownAdapter.getDropDownView(AppCompatSpinner.java:624)
at android.support.v7.widget.AppCompatSpinner$DropDownAdapter.getView(AppCompatSpinner.java:620)
at android.support.v7.widget.AppCompatSpinner.compatMeasureContentWidth(AppCompatSpinner.java:547)
at android.support.v7.widget.AppCompatSpinner.access$500(AppCompatSpinner.java:65)
at android.support.v7.widget.AppCompatSpinner$DropdownPopup.computeContentWidth(AppCompatSpinner.java:738)
at android.support.v7.widget.AppCompatSpinner$DropdownPopup.show(AppCompatSpinner.java:763)
at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:424)
at android.view.View$PerformClick.run(View.java:18675)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Solved it!!
Actually a String value in my List LanguageList was null and that was throwing the exception