我看了其他隐藏进度条的问题,但它们似乎都建议做我已经在做的事情。
我正在尝试使用
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>
mProductListProgressBar
? - kiruwkamProductListProgressBar
设置为相对定位? - kiruwkamProductListProgressBar
是否在其他地方被引用,例如相对于你的进度条的某个其他视图位置。 - kiruwkanull
传递给setEmptyView()
,看看是否可以快速解决问题。同时,在文件中使用grep
命令查找mProductListProgressBar
以确保万无一失。 - kiruwka