我的相对布局有两个子Rcyclerview(不可见)和进度条。
我想要的是:布局的创建,recyclelerview到隐形和进度条显示,直到AsyncTask(从SD文件夹中获取图像)完成,并且recyclerview可见且进度条不可见。
正在发生的事情:我的应用未显示进度条。在asyctask完成后,我的recyclerview出现了。
XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/view3">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:divider="@null"
android:visibility="invisible"
android:id="@+id/recycler_view_cameragallery"
android:dividerHeight="0dp"
android:fadingEdge="none" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar_Gallery"
style="?android:attr/progressBarStyleLarge"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:padding="12dp" />
</RelativeLayout>
ActivityCode:
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,@Nullable Bundle savedInstanceState){
View rootView=inflater.inflate(R.layout.camera_layout,container,false);
rootView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
ButterKnife.inject(this,rootView);
init();
initialise(rootView);
initialiseListeners();
listofImagesPath = new ArrayList<String>();
new mediaScanAyscTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);}
的AsyncTask
public class mediaScanAyscTask extends AsyncTask<Void,Void,Void>{
@Override
protected Void doInBackground(Void... params) {
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
adapter.clearApplications();
galleryProgressBar.setVisibility(View.VISIBLE);
galleryProgressBar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#ff4081"), PorterDuff.Mode.MULTIPLY);
cameraRecyclerView.setVisibility(View.INVISIBLE);
}
@Override
protected void onPostExecute(Void aVoid) {
listofImagesPath = RetriveCapturedImagePath();
if(listofImagesPath!=null){
adapter.addApplications(listofImagesPath);
}
galleryProgressBar.setVisibility(View.INVISIBLE);
cameraRecyclerView.setVisibility(View.VISIBLE);
super.onPostExecute(aVoid);
}
}
请突出我错在哪里帮助我。
答案 0 :(得分:12)
在我的情况下,模拟器在开发者模式下关闭了动画,因此我看不到进度条。
答案 1 :(得分:1)
让你的布局消失而不是隐形
答案 2 :(得分:0)
我希望这个答案可以帮到你。
@Override
protected void onPostExecute(Void aVoid) {
listofImagesPath = RetriveCapturedImagePath();
if(listofImagesPath!=null){
adapter.addApplications(listofImagesPath);
}
galleryProgressBar.setVisibility(View.GONE);
cameraRecyclerView.setVisibility(View.VISIBLE);
super.onPostExecute(aVoid);
}
第二个选项是从ProgressBar
文件中删除.xml
并以编程方式创建。
class YourClassName extends AsyncTask<String, Void, Boolean>{
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(Detail_Activity.this);
dialog.setTitle("your title");
dialog.setMessage("your message");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected Boolean doInBackground(String... params) {
return null;
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
dialog.cancel();
}
}
答案 3 :(得分:0)
我遇到了同样的问题,原因是ProgressBar
位于RecyclerView
的底部。您需要将RecyclerView
和ProgressBar
打包到FrameLayout
。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/view3">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:divider="@null"
android:visibility="invisible"
android:id="@+id/recycler_view_cameragallery"
android:dividerHeight="0dp"
android:fadingEdge="none" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar_Gallery"
style="?android:attr/progressBarStyleLarge"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:padding="12dp" />
</FrameLayout>
</RelativeLayout>
答案 4 :(得分:-1)
Try this
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="100"
android:id="@+id/progress"/>