ho risolto il problema aggiungendo una barra progess al layout e quindi utilizzando un comportamento personalizzato per la barra di avanzamento. Layout:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="es.mediaserver.newinterfacedlna.MainActivity">
<android.support.design.widget.AppBarLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main"
android:id="@+id/include" />
<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_margin="28dp"
android:layout_gravity="bottom|center"
app:srcCompat="@android:drawable/ic_media_play" />
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="bottom|center"
android:indeterminate="true"
android:layout_margin="@dimen/fab_margin"
/>
</android.support.design.widget.CoordinatorLayout>
componente comportamento personalizzato
public static class SnackBarBehavior extends CoordinatorLayout.Behavior<View> {
private static final boolean SNACKBAR_BEHAVIOR_ENABLED;
public SnackBarBehavior() {
super();
}
public SnackBarBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
child.setTranslationY(translationY);
return true;
}
@Override
public void onDependentViewRemoved(CoordinatorLayout parent, View child, View dependency) {
child.setTranslationY(0);
}
static {
SNACKBAR_BEHAVIOR_ENABLED = Build.VERSION.SDK_INT >= 11;
}
}
E infine nella onCreate (o nel layout con app: layout_behavior = "xxx.xxx.SnackBarBehavior")
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar2);
SnackBarBehavior snackBarBehavior = new SnackBarBehavior();
CoordinatorLayout.LayoutParams coordinatorParams = (CoordinatorLayout.LayoutParams) progressBar.getLayoutParams();
coordinatorParams.setBehavior(snackBarBehavior);
Nota: ho basato il mio componente di comportamento in quello pubblicato qui How to move a view above Snackbar just like FloatingButton
fonte
2017-10-12 12:36:39
C'è un modo per utilizzare questo senza alcun supporto di libreria? Solo puro codice nativo. –
Per sfuggire al supporto della libreria: seguire il collegamento, scaricare il progetto dimostrativo e copiare il codice nel proprio progetto. – Zon