【发布时间】:2015-09-09 20:18:37
【问题描述】:
我有一个已实现且看起来不错的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/splash_layout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/splashscreen"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"/>
</LinearLayout>
但是我需要在图像的中心添加一个进度条,所以我有这个起始代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
但是当我尝试将两者结合时,它会将图像推离屏幕。由于某种原因,我不能使用图形布局来渲染它,并试图看看我是否可以让它工作。
我的综合想法是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/splash_layout">
<RelativeLayout
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/splashscreen"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"/>
</LinearLayout>
它似乎只是将图像推离屏幕或其他东西,我无法弄清楚发生了什么。
是否有办法通过将相对布局变为相对或绝对来将相对布局从 dom 中取出?然后图像会向上滑动,但相对布局仍将是 0,0,高度和宽度 == 父级。
【问题讨论】: