Android 我想使我的布局不可聚焦

Android 我想使我的布局不可聚焦,android,Android,我想让我的布局不可聚焦,即:我想用户不能点击布局上的按钮,直到解析完成 我已经做了使按钮不可点击和点击时,解析完成 但是如果我能使布局不可聚焦 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); progress_waiting1=(ProgressBar)findViewById(

我想让我的布局不可聚焦,即:我想用户不能点击布局上的按钮,直到解析完成 我已经做了使按钮不可点击和点击时,解析完成

但是如果我能使布局不可聚焦

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    progress_waiting1=(ProgressBar)findViewById(R.id.progress1);
    progress_waiting1.setVisibility(ProgressBar.VISIBLE);


    progress_waiting2=(ProgressBar)findViewById(R.id.progress2);
    progress_waiting2.setVisibility(ProgressBar.VISIBLE);

    Typeface tf_helvetica = Typeface.createFromAsset(getAssets(),"fonts/HelveticaNw.ttf");
    Typeface tf_helvetica_bold = Typeface.createFromAsset(getAssets(),"fonts/HelveticaNwBd.ttf");

    Config.TF_HELVETICA=tf_helvetica;
    Config.TF_HELVETICA_BOLD=tf_helvetica_bold;



    bttn_bedpress=(ImageButton)findViewById(R.id.bttn_bedpress);
    bttn_news=(ImageButton)findViewById(R.id.bttn_news);
    bttn_logo=(ImageButton)findViewById(R.id.bttn_logo);
    bttn_faq=(ImageButton)findViewById(R.id.bttn_faq);
    bttn_cv=(ImageButton)findViewById(R.id.bttn_cv);
    bttn_omnu=(ImageButton)findViewById(R.id.bttn_omnu);

    bttn_recent=(ImageButton)findViewById(R.id.button1);

    bttn_bedpress.setClickable(false);
    bttn_news.setClickable(false);
    bttn_logo.setClickable(false);
    bttn_faq.setClickable(false);
    bttn_cv.setClickable(false);
    bttn_omnu.setClickable(false);

    bttn_recent.setClickable(false);

    img_gray_bg=(RelativeLayout)findViewById(R.id.img_gray_bg);
    img_gray_bg.setVisibility(ImageView.VISIBLE);

    txt_wait=(TextView)findViewById(R.id.txt_wait);
    txt_wait.setVisibility(TextView.VISIBLE);
    txt_wait.setTypeface(Config.TF_HELVETICA_BOLD);

    topheading=(TextView)findViewById(R.id.txt_topheading);
        topheading.setTypeface(Config.TF_HELVETICA_BOLD);
    headline=(TextView)findViewById(R.id.txt_headline);
        headline.setTypeface(Config.TF_HELVETICA_BOLD);
    date=(TextView)findViewById(R.id.txt_date);
        date.setTypeface(Config.TF_HELVETICA_BOLD);
    txt_place=(TextView)findViewById(R.id.txt_place);
        txt_place.setTypeface(Config.TF_HELVETICA_BOLD);
    img_company=(ImageView)findViewById(R.id.img_company);

    txt_news=(TextView)findViewById(R.id.txt_news);
        txt_news.setTypeface(Config.TF_HELVETICA_BOLD);
    txt_career=(TextView)findViewById(R.id.txt_career);
        txt_career.setTypeface(Config.TF_HELVETICA_BOLD);
    txt_bedpress=(TextView)findViewById(R.id.txt_bedpress);
        txt_bedpress.setTypeface(Config.TF_HELVETICA_BOLD);

    txt_cv=(TextView)findViewById(R.id.txt_cv);
        txt_cv.setTypeface(Config.TF_HELVETICA_BOLD);
    txt_faq=(TextView)findViewById(R.id.txt_faq);
        txt_faq.setTypeface(Config.TF_HELVETICA_BOLD);
    txt_logo=(TextView)findViewById(R.id.txt_logo);
        txt_logo.setTypeface(Config.TF_HELVETICA_BOLD);

        doAction();
}

public void doAction()
{
    progress_waiting1.setVisibility(ProgressBar.VISIBLE);

    progress_waiting2.setVisibility(ProgressBar.VISIBLE);

    img_gray_bg.setVisibility(ImageView.VISIBLE);

    txt_wait.setVisibility(TextView.VISIBLE);

        topheading.setTypeface(Config.TF_HELVETICA_BOLD);
        headline.setTypeface(Config.TF_HELVETICA_BOLD);
        date.setTypeface(Config.TF_HELVETICA_BOLD);
        txt_place.setTypeface(Config.TF_HELVETICA_BOLD);


        txt_news.setTypeface(Config.TF_HELVETICA_BOLD);

        txt_career.setTypeface(Config.TF_HELVETICA_BOLD);

        txt_bedpress.setTypeface(Config.TF_HELVETICA_BOLD);


        txt_cv.setTypeface(Config.TF_HELVETICA_BOLD);

        txt_faq.setTypeface(Config.TF_HELVETICA_BOLD);

        txt_logo.setTypeface(Config.TF_HELVETICA_BOLD);

    if(!HaveNetworkConnection())
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Nettverk ikke tilgjengelig")
               .setCancelable(false)
               .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) 
                   {
                       dialog.cancel(); 
                   }
               });

        AlertDialog alert = builder.create();
        alert.show();
    }

    final Thread parseThread=new Thread(new Runnable() {

        public void run()
        {
            if(HaveNetworkConnection())
            {
                parseDataBedPres(Config.URL_BedPres);
                parseDataNyheter(Config.URL_Nyheter);
                Collections.sort(mydate);

            }
            else
            {
                parseDataBedPresLocal();
                parseDataNyheterLocal();
            }
        }
    });
    parseThread.start();

    Thread displayThread = new Thread(new Runnable() {
        public void run() {

         try
         {
             parseThread.join();
         }
         catch (InterruptedException e) 
         {
            e.printStackTrace();
         }  
         mHandler.post(new Runnable() { 
            public void run() 
            {

                progress_waiting1.setVisibility(ProgressBar.GONE);
                progress_waiting2.setVisibility(ProgressBar.GONE);
                txt_wait.setVisibility(TextView.GONE);
                img_gray_bg.setVisibility(ImageView.GONE);



                String month[]=getResources().getStringArray(R.array.month_array);

                if(data_bedpres_future.size()!=0)
                {
                    int pos=data_bedpres_future.get(0).size()-1;
                    DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
                    Date dt = null;
                    Calendar cal = Calendar.getInstance();
                    try
                    {
                        dt = df.parse(data_bedpres_future.get(1).get(pos));
                        cal.setTime(dt);
                    }
                    catch (ParseException e1) 
                    {
                        e1.printStackTrace();
                    }

                    DateFormat df2=new SimpleDateFormat("hh:mm:ss");
                    Date dt2 = null;
                    Calendar cal2 = Calendar.getInstance();
                    try
                    {
                        dt2 = df2.parse(data_bedpres_future.get(2).get(pos));
                        cal2.setTime(dt2);
                    }
                    catch (ParseException e1) 
                    {
                        e1.printStackTrace();
                    }



                    date.setText("Tid: "+cal.get(Calendar.DATE)+" "+month[cal.get(Calendar.MONTH)]+" kl "+cal2.get(Calendar.HOUR_OF_DAY)+":"+cal2.get(Calendar.MINUTE));

                    //date.setText("Tid : "+data_bedpres_future.get(1).get(0));
                    headline.setText("Neste Bed.pres: "+data_bedpres_future.get(0).get(pos));
                    txt_place.setText("Sted: "+data_bedpres_future.get(3).get(pos));
                    try 
                    {

                            Drawable img = drawable_from_url(data_bedpres_future.get(4).get(pos),"icon");
                            if(img!=null)
                            {
                                int height,width,w;
                                height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight();
                                int ratio =  (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight());
                                int wi    = (img.getMinimumWidth() * ratio) /100;
                                width = img.getMinimumWidth() -wi;
                                w=width;
                                int width1 = width > 211 ? 211 :width;
                                if (width>0) 
                                {
                                    ratio =  (((width - width1)*100)/width);
                                    int hi    = (height * ratio) /100;
                                    height = height -hi;
                                    w=width1;
                                }

                                ViewGroup.LayoutParams params = img_company.getLayoutParams();
                                params.height = height;
                                params.width = w;
                                img_company.setLayoutParams(params);
                                img_company.setBackgroundDrawable(drawable_from_url(data_bedpres_future.get(4).get(pos),"icon"));
                            }

                    } catch (MalformedURLException e) 
                    {
                        e.printStackTrace();
                    } catch (IOException e) 
                    {
                        e.printStackTrace();
                    }
                }
                else if(data_nyheter_future.size()!=0)
                {
                    date.setText(data_nyheter_future.get(2).get(0));
                    headline.setText("Siste nyhet: "+data_nyheter_future.get(3).get(0));    


                    try 
                    {
                        Drawable img = drawable_from_url(data_nyheter_future.get(0).get(0),"icon");
                        if(img!=null)
                        {
                            int height,width,w;
                            height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight();
                            int ratio =  (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight());
                            int wi    = (img.getMinimumWidth() * ratio) /100;
                            width = img.getMinimumWidth() -wi;
                            w=width;
                            int width1 = width > 211 ? 211 :width;
                            if (width>0) 
                            {
                                ratio =  (((width - width1)*100)/width);
                                int hi    = (height * ratio) /100;
                                height = height -hi;
                                w=width1;
                            }

                            ViewGroup.LayoutParams params = img_company.getLayoutParams();
                            params.height = height;
                            params.width = w;
                            img_company.setLayoutParams(params);
                        img_company.setBackgroundDrawable(img);
                    } 
                    }catch (MalformedURLException e) 
                    {
                        e.printStackTrace();
                    } catch (IOException e) 
                    {
                        e.printStackTrace();
                    }
                }
                else if(data_nyheter_past.size()!=0)
                {
                    DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
                    Date dt = null;
                    Calendar cal = Calendar.getInstance();
                    try
                    {
                        dt = df.parse(data_nyheter_past.get(2).get(0));
                        cal.setTime(dt);
                    }
                    catch (ParseException e1) 
                    {
                        e1.printStackTrace();
                    }
                    date.setText("Dato: "+cal.get(Calendar.DATE)+"."+(cal.get(Calendar.MONTH)+1)+"."+cal.get(Calendar.YEAR));
                    headline.setText("Siste nyhet: "+data_nyheter_past.get(3).get(0));  

                    try 
                    {
                        Drawable img = drawable_from_url(data_nyheter_past.get(0).get(0),"icon");
                        if(img!=null)
                        {
                            int height,width,w;
                            height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight();
                            int ratio =  (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight());
                            int wi    = (img.getMinimumWidth() * ratio) /100;
                            width = img.getMinimumWidth() -wi;
                            w=width;
                            int width1 = width > 211 ? 211 :width;
                            if (width>0) 
                            {
                                ratio =  (((width - width1)*100)/width);
                                int hi    = (height * ratio) /100;
                                height = height -hi;
                                w=width1;
                            }

                            ViewGroup.LayoutParams params = img_company.getLayoutParams();
                            params.height = height;
                            params.width = w;
                            img_company.setLayoutParams(params);
                        img_company.setBackgroundDrawable(img);
                    }
                    }
                    catch (MalformedURLException e) 
                    {
                        e.printStackTrace();
                    } catch (IOException e) 
                    {
                        e.printStackTrace();
                    }
                }

                bttn_bedpress.setClickable(true);
                bttn_news.setClickable(true);
                bttn_logo.setClickable(true);
                bttn_faq.setClickable(true);
                bttn_cv.setClickable(true);
                bttn_omnu.setClickable(true);

                bttn_recent.setClickable(true);
            }
        });

        }
    });
    displayThread.start();

您是否考虑过在
AsyncTask
中完成任务,并在完成任务时显示
ProgressDialog


这里有一个使用它们的示例:

您应该删除不重要的代码。只是给下次的提示。。。