就我而言,解决方案有点棘手和有趣。我有RelativeLayout
aTextView
和 a ProgressBar
。位于Progressbar
顶部TextView
,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
tools:context="com.caoa.yakokoe.yakokoe.ui.splash.SplashActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="@string/content_desc_logo_green"
android:src="@drawable/logo_green" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5">
<ProgressBar
android:id="@+id/splash_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/splash_text"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:visibility="gone" />
<TextView
android:id="@+id/splash_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="24dp"
android:layout_marginTop="16dp"
android:text="@string/splash_text_default"
android:textAlignment="center"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
这引发了一种错误(忘记了它是什么,但它在“找不到 layout_above 的 id”的行中)。
解决方案是简单地翻转ProgressBar
和TextView
位置,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
tools:context="com.caoa.yakokoe.yakokoe.ui.splash.SplashActivity">
<!-- Content here -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5">
<TextView
android:id="@+id/splash_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="24dp"
android:layout_marginTop="16dp"
android:text="@string/splash_text_default"
android:textAlignment="center"
android:visibility="gone" />
<ProgressBar
android:id="@+id/splash_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/splash_text"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>