在XML android布局中居中进度条和图像
我有一个android应用程序的加载屏幕在XML android布局中居中进度条和图像,android,xml,layout,Android,Xml,Layout,我有一个android应用程序的加载屏幕 如果我只使用背景图像或PrimeStBar,它工作正常,但是当我试图在屏幕中间对两个元素进行中心处理时,我得到: 到目前为止,我的活动y_main.xml如下所示: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http:
如果我只使用背景图像或PrimeStBar,它工作正常,但是当我试图在屏幕中间对两个元素进行中心处理时,我得到:
到目前为止,我的活动y_main.xml
如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainLayout"
tools:context="com.siconet.axa.MainActivity" >
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/axa_logo" />
<ProgressBar
android:layout_width="250px"
android:layout_height="250px"
android:indeterminate="true" />
</RelativeLayout>
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
我想要实现的是这样的目标:
尝试改用
centerInParent
。类似于
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" > // right here
注意不同的变化,但这个布局给了我以下
我在第二张图片中看不到您的
ImageView
,因此我将它们都居中。如果您可以解释应该在哪里,那么我可以调整此布局。尝试使用centerInParent
。类似于
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" > // right here
注意不同的变化,但这个布局给了我以下
我在第二张图片中看不到您的
ImageView
,因此我将它们都居中。如果您可以解释应该在哪里,那么我可以调整此布局。尝试使用centerInParent
。类似于
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" > // right here
注意不同的变化,但这个布局给了我以下
我在第二张图片中看不到您的
ImageView
,因此我将它们都居中。如果您可以解释应该在哪里,那么我可以调整此布局。尝试使用centerInParent
。类似于
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" > // right here
注意不同的变化,但这个布局给了我以下
我在第二张图片中看不到您的
ImageView
,因此我将它们都居中。如果你能解释应该在哪里,那么我可以调整此布局。尝试将这一行添加到progressBarandroid:layout\u centerInParent=“true”
尝试将这一行添加到progressBarandroid:layout\u centerInParent=“true”
尝试将此行添加到progressBarandroid:layout\u centerInParent=“true”
尝试将此行添加到progressBarandroid:layout\u centerInParent=“true”尝试此布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainLayout"
tools:context="com.siconet.axa.MainActivity" >
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ProgressBar
android:layout_width="250px"
android:layout_height="250px"
android:layout_centerInParent="true"
android:indeterminate="true" />
</RelativeLayout>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
希望这对您有所帮助。试试这个布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainLayout"
tools:context="com.siconet.axa.MainActivity" >
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ProgressBar
android:layout_width="250px"
android:layout_height="250px"
android:layout_centerInParent="true"
android:indeterminate="true" />
</RelativeLayout>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
希望这对您有所帮助。试试这个布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainLayout"
tools:context="com.siconet.axa.MainActivity" >
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ProgressBar
android:layout_width="250px"
android:layout_height="250px"
android:layout_centerInParent="true"
android:indeterminate="true" />
</RelativeLayout>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
希望这对您有所帮助。试试这个布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainLayout"
tools:context="com.siconet.axa.MainActivity" >
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ProgressBar
android:layout_width="250px"
android:layout_height="250px"
android:layout_centerInParent="true"
android:indeterminate="true" />
</RelativeLayout>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
希望这对您有所帮助。尝试使用框架布局而不是“加载面板”中的相对布局尝试使用框架布局而不是“加载面板”中的相对布局尝试使用框架布局而不是“加载面板”中的相对布局尝试使用框架布局而不是“加载面板”中的相对布局看起来更糟(我讨厌布局XDDDD您可以尝试将整个内容包装成线性布局
并使用布局_gravity=“center”
。老实说,这两个图像在我看来是一样的。如果问题是在完成之前不显示webview,那么您可能应该将可见性设置为Goe,因为在第一个图像中,进度条位于图像的一角,在第二个图像中居中……关于可见性
我通过编程方式设置了所需元素的可见性,但这不是问题没问题。webView
是一个phonegap应用程序,我有嵌套的布局loadingPanel
,在需要时在phonegap应用程序的顶部显示进度条……啊,是的,对不起,我不知道我怎么会错过。无论如何,你可以在我的答案中尝试更新布局。我还没有机会测试它,但类似的东西应该可以工作。我已经完成了更新了我的答案,做了一些调整,并显示了一些内容。如果您想要的内容不同,请告诉我。看起来更糟…:(我讨厌布局XDDDD您可以尝试将整个内容包装在线性布局中,然后使用布局\u gravity=“center”
。老实说,这两个图像在我看来是一样的。如果问题是在完成之前不显示webview,那么您可能应该将可见性设置为Goe,因为在第一个图像中,进度条位于图像的一角,在第二个图像中居中……关于可见性
我通过编程方式设置了所需元素的可见性,但这不是问题没问题。webView
是一个phonegap应用程序,我有嵌套的布局loadingPanel
,在需要时在phonegap应用程序的顶部显示进度条……啊,是的,对不起,我不知道我怎么会错过。无论如何,你可以在我的答案中尝试更新布局。我还没有机会测试它,但类似的东西应该可以工作。我已经完成了更新了我的答案,做了一些调整,并显示了一些内容。如果您想要的内容不同,请告诉我。看起来更糟…:(我讨厌布局XDDDD您可以尝试将整个内容包装在线性布局中,然后使用布局\u gravity=“center”
。老实说,这两个图像在我看来是一样的。如果问题是在完成之前不显示webview,那么您可能应该将可见性设置为Goe,因为在第一个图像中,进度条位于图像的一角,在第二个图像中居中……关于可见性
我通过编程方式设置了所需元素的可见性,但这不是问题没问题。webView
是一个phonegap应用程序,我有嵌套的布局loadingPanel
,在需要时在phonegap应用程序的顶部显示进度条……啊,是的,对不起,我不知道我怎么会错过。无论如何,你可以在我的答案中尝试更新布局。我还没有机会测试它,但类似的东西应该可以工作。我已经完成了更新了我的答案,做了一些调整,并显示了一些内容。如果您想要的内容不同,请告诉我。看起来更糟…:(我讨厌布局XDDDD您可以尝试将整个内容包装在线性布局中,然后使用布局\u gravity=“center”
。老实说,在我看来,这两张图片看起来是一样的。如果不想显示的话