实施不确定微调器的最佳实践
Best practice for implementing indeterminate spinner
我一直在尝试许多不同的方法来在片段过渡期间实现适当的进度微调器。像这样:
我遇到的主要问题是,当微调器消失并且(微调器的)背景变得透明时,旧片段仍在显示。我尝试了一些方法但没有成功,而且我觉得我 运行 别无选择。如果有人知道如何干净利落地做到这一点,请告诉我。我还想保留我对片段使用 add
而不是 replace
的方式 我正在使用 DrawerLayout,这是我的布局 XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.citychurchtulsa.cc.citychurchapp.MainActivity"/>
<!--Only holds progress bar, main container will be for fragment display!!!-->
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ViewStub
android:id="@+id/loadSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inflatedId="@+id/subView"
android:layout="@layout/progress_spinner"/>
</RelativeLayout>
<!-- Side navigation drawer UI -->
<ExpandableListView
android:id="@+id/nav_view"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="@color/white"
android:divider="@color/colorPrimary"
android:dividerHeight="@dimen/divider_height"
android:groupIndicator="@android:color/transparent"
android:indicatorLeft="?
android:attr/expandableListPreferredItemIndicatorLeft"/>
</android.support.v4.widget.DrawerLayout>
这个我试过了:
将ProgressBar
放在RelativeLayout
中,然后设置可见性,并在我需要时将RelativeLayout
背景设置为一种颜色,并打开可见性当我不这样做时,关闭和背景透明。在扩展片段 class.
之外完成
同上,但在扩展片段class内完成。这里尝试了两种不同的方法。在一次尝试中,我将项目隐藏在 onViewCreated
中,另一次尝试将项目隐藏在 onStart
.
中
创建一个我使用的空片段,就像我提交的其他片段一样,然后返回提交所需的片段
使用 postDelayed
处理程序,但我不一定喜欢那样,因为所有设备都不同
不管怎样,我觉得我已经尝试了更多,但我的头顶上我想不出别的了。我真的很感激任何帮助。
这是我一直在尝试使用的微调器 display/hide 的代码:
public void enableLoadSpinner(boolean set){
if(set)
{
mainContainer.setVisibility(View.GONE);
loadSpinner.setVisibility(View.VISIBLE);
relativeLayout.setBackgroundResource(R.color.colorSecondary);
}
else
{
mainContainer.setVisibility(View.VISIBLE);
loadSpinner.setVisibility(View.GONE);
relativeLayout.setBackgroundResource(android.R.color.transparent);
}
}
好的,我找到问题了!关于 ProgressBar
和 FragmentTransaction
的观点有问题!!!两者之间发生了某种奇怪的互动,所以我删除了 FragmentTransaction
并使用自定义动画使 ProgressBar
消失。
我一直在尝试许多不同的方法来在片段过渡期间实现适当的进度微调器。像这样:
我遇到的主要问题是,当微调器消失并且(微调器的)背景变得透明时,旧片段仍在显示。我尝试了一些方法但没有成功,而且我觉得我 运行 别无选择。如果有人知道如何干净利落地做到这一点,请告诉我。我还想保留我对片段使用 add
而不是 replace
的方式 我正在使用 DrawerLayout,这是我的布局 XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.citychurchtulsa.cc.citychurchapp.MainActivity"/>
<!--Only holds progress bar, main container will be for fragment display!!!-->
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ViewStub
android:id="@+id/loadSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inflatedId="@+id/subView"
android:layout="@layout/progress_spinner"/>
</RelativeLayout>
<!-- Side navigation drawer UI -->
<ExpandableListView
android:id="@+id/nav_view"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="@color/white"
android:divider="@color/colorPrimary"
android:dividerHeight="@dimen/divider_height"
android:groupIndicator="@android:color/transparent"
android:indicatorLeft="?
android:attr/expandableListPreferredItemIndicatorLeft"/>
</android.support.v4.widget.DrawerLayout>
这个我试过了:
将
ProgressBar
放在RelativeLayout
中,然后设置可见性,并在我需要时将RelativeLayout
背景设置为一种颜色,并打开可见性当我不这样做时,关闭和背景透明。在扩展片段 class. 之外完成
同上,但在扩展片段class内完成。这里尝试了两种不同的方法。在一次尝试中,我将项目隐藏在
onViewCreated
中,另一次尝试将项目隐藏在onStart
. 中
创建一个我使用的空片段,就像我提交的其他片段一样,然后返回提交所需的片段
使用
postDelayed
处理程序,但我不一定喜欢那样,因为所有设备都不同
不管怎样,我觉得我已经尝试了更多,但我的头顶上我想不出别的了。我真的很感激任何帮助。
这是我一直在尝试使用的微调器 display/hide 的代码:
public void enableLoadSpinner(boolean set){
if(set)
{
mainContainer.setVisibility(View.GONE);
loadSpinner.setVisibility(View.VISIBLE);
relativeLayout.setBackgroundResource(R.color.colorSecondary);
}
else
{
mainContainer.setVisibility(View.VISIBLE);
loadSpinner.setVisibility(View.GONE);
relativeLayout.setBackgroundResource(android.R.color.transparent);
}
}
好的,我找到问题了!关于 ProgressBar
和 FragmentTransaction
的观点有问题!!!两者之间发生了某种奇怪的互动,所以我删除了 FragmentTransaction
并使用自定义动画使 ProgressBar
消失。