标签云

微信群

扫码加入我们

WeChat QR Code

i want to use FAB for project's listview for adding items. although i want to set animation for release/hide as scrolling.i do sth like this:MainActivity.java class:public class MainActivity extends Activity{private ListView listView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);fab.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent intent = new Intent(getApplicationContext(),AddActivity.class);startActivity(intent);}});listView = (ListView) findViewById(R.id.ListView); ..}}activity_main.xml:<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:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true"tools:context="vow_note.maxsoft.com.vownote.MainActivity"><include layout="@layout/content_main" /><android.support.design.widget.FloatingActionButtonandroid:id="@+id/fab"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="bottom|end"android:layout_margin="@dimen/fab_margin"android:src="@android:drawable/ic_menu_add" />content_main.xml:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayout android:layout_width="match_parent"android:layout_height="70dp"android:orientation="horizontal"android:gravity="center_vertical|center"android:padding="3dp"android:background="#000000"android:id="@+id/ll"> ...</LinearLayout><ListView android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/ListView"android:layout_gravity="right"android:background="#000000"android:paddingBottom="50dp"></ListView>and at last, FABHideScroll.java:public class FABHideScroll extends FloatingActionButton.Behavior {public FABHideScroll(Context context, AttributeSet attrs) {super();}@Overridepublic void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);//child -> Floating Action Buttonif (child.getVisibility() == View.VISIBLE && dyConsumed > 0) {child.hide();} else if (child.getVisibility() == View.GONE && dyConsumed < 0) {child.show();}}@Overridepublic boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;}}i know there should be a problem in them, because it doesn't run.How can I solve it?thanks alot!


Thanks for your suggestion tutorial, but I have question about how can I defe MainActivity? I have created list view in MyActivity before. So I don’t know which one must be the MainActivity and how can I define another? Thanks.

2019年04月19日31分15秒