在这里,我有一个由多个片段共享的视图寻呼机,它们都包含在TABLayout中,如下所示
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#006699"
android:titleTextColor="#FFFFFF"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="#006699"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/tab_layout"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/order_icon"
android:layout_width="59dp"
android:layout_height="59dp"
android:visibility="visible"
android:layout_gravity="right|bottom"
app:layout_anchor="@id/pager"
app:layout_anchorGravity="bottom|right|end"
android:src="@drawable/order_icon"
android:layout_alignBottom="@+id/pager"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
FAB由所有片段共享.我想在FAB上添加一个onLongClicklistener,我可以通过它在布局上拖动按钮(包括viewPager).我使用onTouchListener和MotionEvent对象完成了上述任务.但是,我无法使用拖放API(释放拖动按钮后按钮消失).
这是代码:
orderIcon = (FloatingActionButton)findViewById(R.id.order_icon);
orderIcon.setTag(IMAGEVIEW_TAG);
// Sets a long click listener for the ImageView
orderIcon.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ClipData.Item item = new ClipData.Item((CharSequence) v
.getTag());
String[] mimeTypes = { ClipDescription.MIMETYPE_TEXT_PLAIN }; …Run Code Online (Sandbox Code Playgroud) android onlongclicklistener android-fragments android-viewpager floating-action-button
android ×1