Android 将进度条放置在按钮后面
我有一个Android 将进度条放置在按钮后面,android,layout,button,progress-bar,android-relativelayout,Android,Layout,Button,Progress Bar,Android Relativelayout,我有一个按钮,它在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_margi
按钮
,它在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" />
<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" />
我想在按钮后面添加一个进度条,它与按钮占据完全相同的空间,这样当按钮被禁用(半透明)时,您可以看到它后面的进度条。我该怎么做呢?将其放在xml中相对布局内的按钮之前:
<ProgressBar
android:id="@+id/descriptive_name"
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"
/>
通过使用所有相同的layout和padding属性,我们可以确保视图位于相同的位置,大小大致相同(高度可能因包裹内容不同而不同),我认为如果您首先在布局文件中放置进度条,那么按钮应该出现在顶部
但是,您也可以使用view.setVisibility(visibility ness)
强制执行您想要的任何策略,只要确保在使其中一个可见时,另一个不可见即可
这样,如果我根据它们在文件中的位置(我可能是,我刚才没有验证它),在默认情况下它们是如何堆叠的,并且如果您不想移动进度条以在文件中显示按钮,从用户的角度来看,您仍然可以实现同样的效果。将此项放在xml中相对布局内的按钮之前:
<ProgressBar
android:id="@+id/descriptive_name"
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"
/>
通过使用所有相同的layout和padding属性,我们可以确保视图位于相同的位置,大小大致相同(高度可能因包裹内容不同而不同),我认为如果您首先在布局文件中放置进度条,那么按钮应该出现在顶部
但是,您也可以使用view.setVisibility(visibility ness)
强制执行您想要的任何策略,只要确保在使其中一个可见时,另一个不可见即可
这样,如果我根据它们在文件中的位置(我可能是,我刚才没有验证它),在默认情况下它们是如何堆叠的,并且如果您不想移动进度条以在文件中显示按钮,从用户的角度来看,您仍然可以实现同样的效果。要做到这一点,我必须首先在我的
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" />
<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" />
最终结果
按钮启用时:
使用进度条禁用时的按钮:
为此,我必须首先在我的
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" />
<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" />
最终结果
按钮启用时:
使用进度条禁用时的按钮:
将进度条放置在按钮后面,但进度条的宽度大于按钮的宽度。此外,进度条的高度要小得多。这将进度条放在按钮后面,但进度条的宽度大于按钮的宽度。此外,进度条的高度要小得多。