【问题标题】:How can I replace an imageButton with progressBar while waiting for a request?如何在等待请求时用 progressBar 替换 imageButton?
【发布时间】:2014-06-18 12:54:34
【问题描述】:

我想在处理请求时用进度条替换图像按钮。

这是我的 XML

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/gap_normal"
    android:orientation="horizontal"
    android:background="0000000000">


    <com.devspark.robototextview.widget.RobotoTextView
        android:id="@+id/conference_text_lockstate"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/gap_normal"
        android:layout_marginBottom="@dimen/gap_normal"
        android:gravity="left"
        android:textSize="@dimen/textsize_normal"
        android:paddingRight="@dimen/gap_large"
        android:text="Unlocked. When all participants have joined, lock the conference by tapping the padlock."
        app:typeface="roboto_condensed_regular" />


    <ImageButton
        android:id="@+id/conference_checkableimagebutton_lockstate"
        android:layout_width="60dp"
        android:layout_height="match_parent"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        android:background="@android:color/white"
        android:src="@drawable/conference_checkableimagebutton_lockstate_src"
        android:cropToPadding="false"/>


    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pb"
        android:indeterminate="true"
        android:visibility="invisible"
        />




</LinearLayout>    

我尝试在 onClick 方法中将 Image 按钮与 progressBar 交换。

          if (mLockCheckableImageButton.isChecked()==true){

                mLockCheckableImageButton.setClickable(false);

                ProgressBar pb = (ProgressBar)inflated.findViewById(R.id.pb);

                pb.setVisibility(View.VISIBLE);    

         //more code here.

但这会使它们彼此相邻。任何人?提前谢谢你。

【问题讨论】:

  • 使用相对或框架布局...
  • 如果你只想替换,那么你忘了调用 mLockCheckableImageButton.setVisibility(View.GONE);

标签: android xml mobile android-studio


【解决方案1】:
 Private void showProgressBar() {
myProgressBar.setVisibility(View.VISIBLE);
myImageButton.setVisibility(View.GONE);
}

private void showImageButton() {
myProgressBar.setVisibility(View.GONE);
myImageButton.setVisibility(View.VISIBLE);
}

【讨论】:

    【解决方案2】:

    您将ProgressBar 的可见性设置为visible。但是您不会更改ImageButton 的可见性。这就是它们都显示的原因。

    首先,您应该使用RelativeLayoutFrameLayout,以便这些视图可以位于同一位置(使用LinearLayout,它们将并排)。然后创建方法来显示这些元素之一:

    private void showProgressBar() {
        myProgressBar.setVisibility(View.VISIBLE);
        myImageButton.setVisibility(View.INVISIBLE);
    }
    
    private void showImageButton() {
        myProgressBar.setVisibility(View.INVISIBLE);
        myImageButton.setVisibility(View.VISIBLE);
    }
    

    【讨论】:

      【解决方案3】:

      试试这个!

      mLockCheckableImageButton.setOnClickListener(new View.OnClickListener() {
      
                      @Override
                      public void onClick(View v) {
                          // TODO Auto-generated method stub
                                      mLockCheckableImageButton.setVisibility(View.GONE);    
                          pb.setVisibility(View.VISIBLE);    
      
                      }
              });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-21
        • 1970-01-01
        • 2018-07-10
        • 2017-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多