如何在线性布局中放置进度对话框:Android

如何在线性布局中放置进度对话框:Android,android,android-linearlayout,progressdialog,Android,Android Linearlayout,Progressdialog,我的片段有一个相对的布局。 在这个布局中,我有一堆子视图,其中一个是线性布局,它显示了一些图形数据。 这些数据来自云,因此需要一些时间。 虽然这些数据正在进行中,但我希望显示一个进度对话框,但仅在线性布局的地方,我希望片段的其余部分仍然可见,并且用户应该能够使用其余的视图 有人能提出一些建议吗 谢谢 UDPATE:添加包含相对布局rl_layout.XML的XML布局文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayou

我的片段有一个相对的布局。 在这个布局中,我有一堆子视图,其中一个是线性布局,它显示了一些图形数据。 这些数据来自云,因此需要一些时间。 虽然这些数据正在进行中,但我希望显示一个进度对话框,但仅在线性布局的地方,我希望片段的其余部分仍然可见,并且用户应该能够使用其余的视图

有人能提出一些建议吗

谢谢

UDPATE:添加包含相对布局rl_layout.XML的XML布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/age_txt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:layout_marginLeft="10dip"
        android:gravity="left"
        android:textSize="30sp"/>

     <TextView
        android:id="@+id/time_txt"
        android:layout_toRightOf="@id/age_txt"
        android:layout_alignBaseline="@id/age_txt"
        android:paddingLeft="5dip"
        android:layout_marginBottom="5dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:textSize="20sp"
        android:text="AM/PM"/>


    <LinearLayout
        android:id="@+id/photo_pic_layout"
        android:layout_width="wrap_content"
        android:layout_height="180dip"
        android:layout_below="@+id/plug_chart_title_txt"
        android:layout_centerHorizontal="true"
        android:layout_margin="10dip"
        android:orientation="vertical"
        android:background="@android:color/white" >
    </LinearLayout>


     <Switch
         android:id="@+id/switch"
         android:layout_width="160dip"
         android:layout_height="35dip"
         android:track="@drawable/btntoggle_selector" 
         android:layout_below="@id/photo_pic_layout"
         android:thumb="@drawable/button"
         android:textOn=""
         android:thumbTextPadding="40dip"
         android:textOff=""
         android:layout_margin="10dip"
         android:layout_centerHorizontal="true"
         />

</RelativeLayout>


我想显示进度对话框来代替线性布局:@id/photo\u pic\u layout

您可以使用进度栏来显示背景工作


不能在布局中添加进度对话框。进度对话框是活动窗口上的窗口上下文。显示进度对话框时,您不能触摸活动中的视图。如果在进度对话框外部触摸,则如果设置了
progressDialog.setCancelable(true)
progressDialog.setCancelOnTouchSie(true)
,,则对话框将关闭。有关使用进度条执行异步任务的完整示例,请参见:

可以异步加载图像,并在线性布局中显示进度条

你需要一个

类似这样的,来源:()

类BitmapWorkerTask扩展了AsyncTask{
私有最终WeakReference imageViewReference;
私有整数数据=0;
公共位图工作任务(ImageView ImageView){
//使用WeakReference确保可以对ImageView进行垃圾收集
imageViewReference=新的WeakReference(imageView);
}
//在背景中解码图像。
@凌驾
受保护位图doInBackground(整数…参数){
数据=参数[0];
返回decodeSampledBitmapFromResource(getResources(),data,100100));
}
//完成后,查看ImageView是否仍然存在并设置位图。
@凌驾
受保护的void onPostExecute(位图){
if(imageViewReference!=null&&bitmap!=null){
最终ImageView=imageViewReference.get();
如果(imageView!=null){
设置图像位图(位图);
}
}
}
}
要在布局文件中添加进度条,请执行以下操作:

 <LinearLayout
     android:orientation="horizontal"
     ... >
     <ProgressBar
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         style="@android:style/Widget.ProgressBar.Small"
         android:layout_marginRight="5dp" />
     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/loading" />
 </LinearLayout>

编辑:关于你的评论

你试过这个吗

<LinearLayout
        android:id="@+id/photo_pic_layout"
        android:layout_width="wrap_content"
        android:layout_height="180dip"
        android:layout_below="@+id/plug_chart_title_txt"
        android:layout_centerHorizontal="true"
        android:layout_margin="10dip"
        android:orientation="vertical"
        android:background="@android:color/white" >

             <ProgressBar
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             style="@android:style/Widget.ProgressBar.Small"
             android:layout_marginRight="5dp" />

    </LinearLayout>


它是否显示了进度条?

但问题是,在进度对话框消失之前,用户不会使用该片段。ProgramPressDialog.setCancelable(false)和progressDialog.setCancelOnTouchOutsie(false)。在工作完成之前,用户不能使用片段。工作完成后,别忘了调用progressDialog.Disclose()。但是否可以将进度条添加到线性布局中是的,进度条可能只是另一个视图,可以添加到视图组(如线性布局)(注意:请参见编辑教程)您是否能够遵循,或者我是否需要逐步编辑答案Nope,我想我明白了。但我唯一关心的是,这个线性布局是在一个相对布局中的,它是片段的视图。所以,cld u请显示代码将其放入LL。你能编辑你的问题并发布你的片段布局文件吗
<LinearLayout
        android:id="@+id/photo_pic_layout"
        android:layout_width="wrap_content"
        android:layout_height="180dip"
        android:layout_below="@+id/plug_chart_title_txt"
        android:layout_centerHorizontal="true"
        android:layout_margin="10dip"
        android:orientation="vertical"
        android:background="@android:color/white" >

             <ProgressBar
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             style="@android:style/Widget.ProgressBar.Small"
             android:layout_marginRight="5dp" />

    </LinearLayout>