eclipse Android ProgressBar .xml 布局
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12290627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android ProgressBar .xml Layout
提问by tcd
I have this for an XML
file:
我有这个XML
文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="visible" />
<WebView
android:id="@+id/web_engine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone" />
</LinearLayout>
And I want the ProgressBar
to be the Large
style, and be centered in the middle of the screen vertically and horizontally... When I set layout_width
and height
to fill_parent
, it increases the size of the actual loading spinner to the entire screen... How can I make the layout fit the entire screen and center the actual loading icon?
我希望ProgressBar
成为Large
风格,并在垂直和水平方向居中于屏幕中间......当我设置layout_width
和height
to 时fill_parent
,它会将实际加载微调器的大小增加到整个屏幕......我该如何制作布局适合整个屏幕并使实际加载图标居中?
回答by Michal
I have checked few possibilities and in my experience the best option for such task is:
我已经检查了几种可能性,根据我的经验,执行此类任务的最佳选择是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:visibility="visible" />
<WebView
android:id="@+id/web_engine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="gone" />
</RelativeLayout>
I am using RelativeLayout
with android:layout_centerInParent="true"
which works better than LinearLayout
.
我使用RelativeLayout
与android:layout_centerInParent="true"
该作品比更好LinearLayout
。
Cheers
干杯
回答by Marcin S.
You can also use FrameLayout insetad of LinearLayout. That way visible view will overlap invisible one. I revised you code:
您还可以使用 LinearLayout 的 FrameLayout insetad。这样可见视图将与不可见视图重叠。我修改了你的代码:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
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_gravity="center_vertical|center_horizontal"
android:visibility="visible" />
<WebView
android:id="@+id/web_engine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone" />
</FrameLayout>