FloatingActionButton
FloatingActionButton copied to clipboard
FAB position changes when listview's setAdapter() is called
As you can see in this video, the fab position is changing when the fragment loads. After debugging it, I found that the listview "setAdapter()" method causes the position change. I don't have a clue why it's happening..
My layout:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/AppTheme.ActionBar" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/toolbar">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sad_face"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_leagues" />
</LinearLayout>
</FrameLayout>
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab_new_league"
android:src="@drawable/ic_action_add"
app:fab_colorNormal="@color/orange"
app:fab_colorPressed="@color/redDark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@id/toolbar"
android:layout_marginBottom="-28dp"
android:layout_marginRight="28dp"
android:elevation="8dp"/>
</RelativeLayout>
My fragment
public class LeagueListFragment extends MyFragment {
@InjectView(android.R.id.list) ListView mListView;
@InjectView(android.R.id.empty) LinearLayout mEmpty;
public static Fragment newInstance() {
return new LeagueListFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_league_list, container, false);
ButterKnife.inject(this, view);
// Fetch league list and set up adapter
List<League> list = League.getAll();
mAdapter = new LeagueAdapter(getActivity(), list);
// Set up ListView
mListView.setEmptyView(mEmpty);
mListView.setDivider(new ColorDrawable(getResources().getColor(R.color.gray)));
mListView.setDividerHeight(2);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
return view;
}
}
Could you try to switch shadow off and check? It seems the method setMarginsWithoutShadow
causes this movement.
Works fine without shadow, how can I implement it with the shadow?
I don't know for now. Currently FAB's margin is changed in the runtime on pre-Lollipop because shadow mustn't be taken into account when margins are set.
@makovkastar @ido567 I am experiencing the exact same issue. is there any way around to have a shadow and this not getting this behaviour?
I didn't find a way to implement the shadow without the bug :\
@ido567 what I ended up doing was I hide(false)
in onViewCreate
and do show()
in onResume
. this will avoid showing jitter move. I know it is not an ideal but IMO okay workaround.
Sounds good, I'll check it out Thank
that doesn't help when using a transition with the button…would be nice if this were fixed.