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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:56:39  来源:igfitidea点击:

Android ProgressBar .xml Layout

androideclipseprogress-barandroid-progressbar

提问by tcd

I have this for an XMLfile:

我有这个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 ProgressBarto be the Largestyle, and be centered in the middle of the screen vertically and horizontally... When I set layout_widthand heightto 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_widthheightto 时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 RelativeLayoutwith android:layout_centerInParent="true"which works better than LinearLayout.

我使用RelativeLayoutandroid: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>