所以我检查了其他问题以隐藏进度条,但似乎都建议做我正在做的事情。
我正在尝试使用
mProductListProgressBar.setVisibility(View.GONE);
我正在通过
找到它mProductListProgressBar = (ProgressBar) mRoot.findViewById(R.id.product_list_progressbar);
我知道这是正确的进度条,因为我可以使用各种LayoutParams命令在屏幕上移动它。但它不会隐藏。
我当前的代码(包括移动进度条)是
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
mProductListProgressBar.setVisibility(View.GONE);
mProductListErrorTextView.setVisibility(View.VISIBLE);
mProductListErrorTextView.setText(errorMessage);
进度条向左和向下移动但仍然可见。我尝试了View.INVISIBLE以及View.GONE,但都没有工作。
这让我疯了!
由于
更新1
protected void showError(int errorMessage){
/*RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
mProductListProgressBar.setLayoutParams(params);
*/
mProductListProgressBar.setVisibility(View.GONE);
mProductListErrorTextView.setVisibility(View.VISIBLE);
mProductListErrorTextView.setText(errorMessage);
}
并用
调用它showError(R.string.wish_list_empty);
更新2
片段的xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<GridView
android:id="@+id/product_list_gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:horizontalSpacing="@dimen/standardMargin"
android:listSelector="@android:color/transparent"
android:numColumns="@integer/columns"
android:scrollbarStyle="outsideOverlay"
android:verticalSpacing="@dimen/standardMargin" />
<RelativeLayout
android:id="@+id/product_list_header"
android:layout_width="match_parent"
android:layout_height="@dimen/refineHeaderHeight"
android:background="@drawable/product_list_header"
android:visibility="gone" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:src="@drawable/dropdown_image" />
<TextView
android:id="@+id/product_list_header_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center|left"
android:paddingLeft="10dp"
android:textAllCaps="true"
android:textColor="@android:color/black"
android:textIsSelectable="false"
android:textSize="@dimen/standardTextSize" />
<TextView
android:id="@+id/product_list_refine_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@drawable/button"
android:clickable="true"
android:gravity="center_vertical"
android:paddingLeft="20dp"
android:paddingRight="30dp"
android:text="@string/refine"
android:textAllCaps="true"
android:textColor="#838383"
android:textSize="@dimen/standardTextSize" />
</RelativeLayout>
<LinearLayout
android:id="@+id/product_list_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="@drawable/product_list_footer"
android:gravity="center"
android:orientation="horizontal"
android:padding="15dp"
android:visibility="gone" >
<ProgressBar
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:background="@android:color/transparent"
android:gravity="center" />
<TextView
android:id="@+id/product_list_footer_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/loading_message"
android:textAllCaps="true"
android:textSize="@dimen/standardTextSize" />
</LinearLayout>
<ProgressBar
android:id="@+id/product_list_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"/>
<TextView
android:id="@+id/product_list_error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAllCaps="true"
android:textSize="@dimen/standardTextSize"
android:visibility="gone" />
<TextView
android:id="@+id/debug"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#aa000000"
android:gravity="left|center_vertical"
android:minLines="2"
android:padding="10dp"
android:textColor="@android:color/white"
android:visibility="gone" />
</RelativeLayout>
答案 0 :(得分:2)
当您尝试隐藏的视图需要/被其他人引用时,通常会出现此行为的问题。
在您的情况下,正如您在评论中提到的那样,您对mProductListProgressBar
的{{1}}使用了setEmptyView()
。
当您的相对容器布局中的其他视图将其位置相对设置为GridView
时,遇到类似问题的另一种可能性。此设置可以是代码,也可以是.xml。
请确保您没有上述任何内容,View.GONE应该可以正常工作。
至于setEmptyView() - 它仅用于在适配器为空时向用户显示有意义的内容。我建议只为中间设置简单的布局,例如mProductListProgressBar
,然后将其传递给TextView "no items"
希望有所帮助。
答案 1 :(得分:1)
对我有用的解决方案是用XML隐藏视图:
android:visibility="gone"
然后在需要时取消隐藏/隐藏它:
yourProgressBar.setVisibility(View.VISIBLE) // or View.VISIBLE depending on situation
答案 2 :(得分:0)
我不知道您的代码是如何编写的,但有类似的问题,并通过从声明
中删除视图对象来解决像
mProductListProgressBar = (ProgressBar) mRoot.findViewById(R.id.product_list_progressbar);
应该是
mProductListProgressBar = (ProgressBar) findViewById(R.id.product_list_progressbar);
尝试并检查
原因是进度条位于层次结构中每个视图的顶部,并且它不属于任何根视图。
答案 3 :(得分:0)
我知道这是一个老问题。但我只是花了很多时间调试类似的情况。我无法在unityPlayer视图之上隐藏ProgressBar。
要确保的另一件事是你在UI线程中隐藏它。
使用以下方法确保环绕您的UI代码:
runOnUiThread(new Runnable() {
@Override
public void run() {
loadingIndicator.setVisibility(View.GONE);
}
});