我嘗試添加甩幹過程可視化我的Android應用程序,並使其複雜的緣故,我目前只啓動它在我的onCreate,而不是結束它,因爲它應該很容易做到這一點。但是,按照官方Android文檔進度條指定只包含的Android不確定的進度條顯示不出來
<ProgressBar
android:id="@+id/weather_loading_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
對於不確定的加載欄,它不起作用。我已經嘗試添加indeterminate
和visibility
,但沒有運氣。
<ProgressBar
android:id="@+id/weather_loading_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible"
/>
我使用科特林的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"
/>
您需要提供您的整個activity_main.xml中的文件,以確定爲什麼進度條不顯示。 –
這很可能是您的佈局問題,而不是Kotlin。 – FWeigl
我已經先行一步,並取得了編輯爲包括佈局 – Rafa