正如您在附加代码中看到的那样,linearLayoutLogo
包含ProgressBar
和TextView
,linearLayoutReading
包含ImageView
和TextView
。当linearLayoutReading
可见时,由于android:layout_centerInParent="true"
,两个布局会围绕中心点重新定位。
我如何设置linearLayoutLogo
动画,以便在linearLayoutReading
变为可见之前向上移动到新位置?请参阅附件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 :(得分:2)
在Android Studio上测试过。只需在最高android:animateLayoutChanges="true"
(LinearLayout
元素之一)中加入centerInParent
。