Android不确定ProgressBar没有显示

时间:2017-10-05 15:08:09

标签: android kotlin android-progressbar kotlin-android-extensions

我正在尝试为我的Android应用添加旋转进度视觉效果,并且为了使其变得复杂,我目前只在我的onCreate中启动而不是结束它,因为它应该非常简单那是对的。但是,遵循进度条的官方Android文档,其中指定只包括

<ProgressBar
    android:id="@+id/weather_loading_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
/>

对于不确定的加载栏,它不起作用。我尝试过添加indeterminatevisibility,但没有运气。

<ProgressBar
    android:id="@+id/weather_loading_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminate="true"
    android:visibility="visible"
/>

我正在使用Kotlin的Android扩展程序,所以在onCreate()我试过了

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    //setVisibility here doesn't actually get shown as an option in the autocomplete, but still compiles.
    weather_loading_bar.setVisibility(View.VISIBLE)
}

但是当我的应用启动时,没有进度条。

编辑:这是整个activity_main布局

<RelativeLayout 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"
tools:context=".ui.MainActivity">

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/currentData"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardBackgroundColor="@color/blue"
    card_view:cardCornerRadius="0dp"
    card_view:cardMaxElevation="25dp">

    <RelativeLayout
        android:id="@+id/cardviewLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp">

        <LinearLayout
            android:id="@+id/temperature_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="10sp"
                tools:text="this is the time" />

            <TextView
                android:id="@+id/temperature"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="25sp"
                tools:text="50°" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/feel_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Feels Like"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/feels"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="25sp" />

        </LinearLayout>

        <!-- Layout Middle-->

        <LinearLayout
            android:id="@+id/forecast_summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="30dp">

            <ImageView
                android:id="@+id/current_icon"
                android:layout_width="100dp"
                android:layout_height="100dp" />

            <TextView
                android:id="@+id/summary_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="15sp" />
        </LinearLayout>

        <!-- End Layout Middle -->

        <!-- Layout bottom -->

        <LinearLayout
            android:id="@+id/precip_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/forecast_summary"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Chance of Rain"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/precipitation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="25sp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/wind_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/forecast_summary"
            android:layout_weight="1"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Wind Speed"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/wind"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="25sp" />
        </LinearLayout>

        <!-- End layout bottom -->

    </RelativeLayout>

</android.support.v7.widget.CardView>

<view
    android:id="@+id/recycler_view"
    class="android.support.v7.widget.RecyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/currentData"
    android:layout_centerInParent="true" />

<ProgressBar
    android:id="@+id/weather_loading_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminate="true"
    android:visibility="visible"
/>

2 个答案:

答案 0 :(得分:0)

您的布局存在一些大问题。首先,您没有在进度条应显示的布局中指定。您需要添加与父RelativeLayout相关的边界。

第二个是,RelativeLayoutFrameLayout的扩展,它从后到前堆叠视图。因此,您的进度条位于布局的后面,前面有CardView(以及其中的所有内容)。

答案 1 :(得分:-1)

放置

<ProgressBar
    android:id="@+id/weather_loading_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminate="true"
    android:visibility="visible"
/>

位于Recycler视图下方RelativeLayout的底部。

相关问题