Dan*_*bbs 1 layout android button relativelayout progress-bar
我有一个Button定义RelativeLayout如下:
<Button
android:id="@+id/search_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/current_location"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="30dp"
android:paddingTop="30dp"
android:text="@string/search" />
Run Code Online (Sandbox Code Playgroud)
我想在Button后面添加一个ProgressBar,占用与Button完全相同的空间,这样当按钮被禁用(半透明)时,你可以看到它背后的进度条.我该怎么做?
要做到这一点,我必须在我的main.xml第一个按钮中定义按钮,然后是进度条,如下所示:
<Button
android:id="@+id/search_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/current_location"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="30dp"
android:paddingTop="30dp"
android:text="@string/search" />
<ProgressBar
android:id="@+id/cooldown_bar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/search_button"
android:layout_below="@id/current_location"
android:layout_marginBottom="6dp"
android:layout_marginLeft="9dp"
android:layout_marginRight="9dp"
android:layout_marginTop="1dp"
android:indeterminate="false"
android:progressDrawable="@drawable/progress_bar" />
Run Code Online (Sandbox Code Playgroud)
然后,一旦我初始化了所有GUI组件,我就不得不将按钮带回进度条前面:
searchButton.bringToFront();
Run Code Online (Sandbox Code Playgroud)
启用时按钮:

使用进度条禁用按钮:
