2016-05-06 11 views
0

Wie Sie in der beigefügten Code sehen können, enthält linearLayoutLogo eine ProgressBar und TextView und linearLayoutReading enthält eine ImageView und TextView. Wenn linearLayoutReading sichtbar gemacht wird, positionieren sich die beiden Layouts aufgrund von android:layout_centerInParent="true" um den Mittelpunkt herum neu.Animieren, wenn Neupositionierung eine Ansicht

Wie kann ich linearLayoutLogo animieren, so dass es nach oben zu seiner neuen Position verschiebt, bevor linearLayoutReading sichtbar wird? Bitte beachten Sie die beigefügte video for an example.

activity_main.xml

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_centerInParent="true" 
    android:gravity="center"> 

    <LinearLayout 
     android:id="@+id/linearLayoutLogo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:gravity="center"> 

     <ImageView 
      android:id="@+id/imageViewRLogo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_accessibility_black_24dp" 
      android:padding="8dp"/> 

     <TextView 
      android:id="@+id/textViewAppTitle2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="34sp" 
      android:textColor="#CCFFFFFF" 
      android:text="AppName"/> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayoutReading" 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="24dp"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/Base.TextAppearance.AppCompat.Large" 
      android:text="Reading from device" 
      android:textColor="#BF000000" /> 
     <ProgressBar 
      android:id="@+id/progressBarSplash" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal" 
      android:paddingBottom="8dp"/> 

    </LinearLayout> 

</LinearLayout> 

MainActivity.java

public class MainActivity extends AppCompatActivity { 
public ProgressBar progressBarSplash; 
public LinearLayout linearLayoutReading; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    linearLayoutReading = (LinearLayout)findViewById(R.id.linearLayoutReading); 
    linearLayoutReading.setVisibility(View.GONE); 

    new CountDownTimer(5000, 1000) { 

     public void onTick(long millisUntilFinished) { 
     } 

     public void onFinish() { 
      linearLayoutReading.setVisibility(View.VISIBLE); 
      progressBarSplash = (ProgressBar)findViewById(R.id.progressBarSplash); 
      progressBarSplash.setEnabled(true); 
      progressBarSplash.setIndeterminate(true); 
     } 
    }.start(); 
} 
} 
+0

Haben Sie versucht mit 'android: animateLayoutChanges =" true "'? –

Antwort

2

es auf Android Studio getestet werden. Fügen Sie einfach android:animateLayoutChanges="true" in die oberste LinearLayout (die mit centerInParent Element).

+0

Das ist wirklich erstaunlich. Eine Zeile bringt genau das, was ich wollte! Vielen Dank. –

+0

Meine exakt gleiche Reaktion, als ich sie das erste Mal zuvor gesehen habe. Prost! : D –