Ich möchte eine Gruppe von Ansichten in einem ConstraintLayout ausblenden. Mit einem LinearLayout würde ich die Ansichten so umbrechen, dass sie in einem übergeordneten LinearLayout ausgeblendet und den übergeordneten animiert werden. Ist das auch der bevorzugte Ansatz für ConstraintLayout? Es hat den Eindruck, dass dies den Zweck einer ConstraintLayoutConstraintLayout: mehrere Ansichten gleichzeitig animieren
1
A
Antwort
2
besiegen würde. Ein Ansatz besteht darin, die Vorteile von zu nutzen.
Sie beginnen mit den ursprünglichen Einschränkungen für die Ansichten im Layout, erstellen einen zweiten Satz von Integritätsbedingungen und wechseln dann zu den neuen Integritätsbedingungen, indem Sie sie "anwenden".
In diesem Beispiel wird die zweite Integritätsregel aus einer nahezu identischen Layoutdatei abgeleitet. Der einzige Unterschied besteht darin, dass die ImageViews auf visibility = "invisible" gesetzt sind.
MainActivity.java
public class MainActivity extends AppCompatActivity {
private ConstraintLayout constraintLayout;
private ConstraintSet originalConstraints = new ConstraintSet();
private ConstraintSet invisibleImageConstraints = new ConstraintSet();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
constraintLayout = (ConstraintLayout)findViewById(R.id.activity_main);
originalConstraints.clone(this, R.layout.activity_main);
invisibleImageConstraints.clone(this, R.layout.activity_main_invisible_images);
}
public void fadeOut(View v) {
TransitionManager.beginDelayedTransition(constraintLayout);
invisibleImageConstraints.applyTo(constraintLayout);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.albertcbraun.constraintlayouttest.MainActivity">
<ImageView
android:id="@+id/image_view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/btn_star_big_on"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:contentDescription="@string/todo"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/image_view_2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintBottom_toTopOf="@+id/button" />
<ImageView
android:id="@+id/image_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/btn_star_big_on"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/image_view_1"
app:layout_constraintVertical_bias="0.481"
android:contentDescription="@string/todo"
app:layout_constraintHorizontal_bias="0.5" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:onClick="fadeOut"
android:text="@string/fade_out"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
activity_main_invisible_images.xml
<android.support.constraint.ConstraintLayout
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/activity_main_invisible_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.albertcbraun.constraintlayouttest.MainActivity">
<ImageView
android:id="@+id/image_view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
app:srcCompat="@android:drawable/btn_star_big_on"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:contentDescription="@string/todo"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/image_view_2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintBottom_toTopOf="@+id/button" />
<ImageView
android:id="@+id/image_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
app:srcCompat="@android:drawable/btn_star_big_on"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/image_view_1"
app:layout_constraintVertical_bias="0.481"
android:contentDescription="@string/todo"
app:layout_constraintHorizontal_bias="0.5" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:onClick="fadeOut"
android:text="@string/fade_out"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
Verwandte Themen
- 1. ConstraintLayout: Wie programmgesteuert mehrere Ansichten hinzufügen?
- 2. iOS. OpenGL. Mehrere Ansichten gleichzeitig
- 3. Leinwand - Wie animieren Sie mehrere Bilder gleichzeitig?
- 4. Anwenden einer Animation auf mehrere Ansichten gleichzeitig
- 5. Constraints und Rahmen gleichzeitig animieren
- 6. ng-animieren mehrere Tabellenzeilen animieren nicht
- 7. Programmgesteuerte Verbindung mehrerer Ansichten auf eine beliebige Größe mit ConstraintLayout
- 8. Django zwei Ansichten gleichzeitig ausführen
- 9. Django Mehrere Attribute gleichzeitig rendern?
- 10. RecyclerView Re-animieren Ansichten beim Scrollen
- 11. eine Gruppe von Ansichten, die eine Kette in einem ConstraintLayout
- 12. Wie kann ich zwei UIView-Reiseleistungen gleichzeitig animieren?
- 13. Mehrere Listenfelder gleichzeitig scrollen?
- 14. Mehrere Indizes gleichzeitig erstellen
- 15. Mehrere Geste Responder gleichzeitig
- 16. mehrere Threads gleichzeitig
- 17. Mehrere Eventlistener gleichzeitig hinzufügen
- 18. Mehrere Tasten gleichzeitig drücken
- 19. Mehrere Ganzzahlen gleichzeitig drucken
- 20. Tomcat mehrere Instanzen gleichzeitig
- 21. Mehrere Lösungsplattformen gleichzeitig erstellen?
- 22. Mehrere Junit-Testfälle gleichzeitig
- 23. Mehrere Threads gleichzeitig ausführen
- 24. Versuchen, zwei UIViews gleichzeitig zu animieren, bewegt sich nur
- 25. Animieren mehrerer Objekte gleichzeitig in AngularJS erzeugt abgehackte Animation
- 26. Mehrere Ansichten erstellen
- 27. Android UI Mehrere Ansichten
- 28. WPF CollectionViewSource Mehrere Ansichten?
- 29. Schienen bilden mehrere Ansichten?
- 30. iphone mehrere Ansichten
Warum nicht die gleiche Animation auf alle Zielansichten anwenden und sie dann mit 'AnimatorSet.playTogether (...)' zusammen starten? – MatPag
Das scheint auf dem Animationsrahmen schwer –