回答
將textview和一個進度條小部件包裝成合適的佈局。更多關於ProgressBar這裏: http://developer.android.com/reference/android/widget/ProgressBar.html
這樣的事情是不可能的,只是一個TextView IMO。我想最好的方式來模仿這種效果將是一個LinearLayout Textview和Imageview(水平方向)。最初讓imageview看不見。有條件地切換imageview的可見性。也就是說,當動作開始時,設置可見性,當動作結束時,再次隱藏它。希望你明白。
一組外佈局的FrameLayout,TextView的/ EditText上和進度內設置
(layout gravity "Right")
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="24dp"
android:text="Getting Location"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="12dp" >
<requestFocus />
</TextView>
<ProgressBar
android:id="@+id/ProgressBar01"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="4dp" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" >
<EditText
android:id="@+id/EditText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="24dp"
android:text="http://example.com"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="12dp" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="4dp" />
</FrameLayout>
我做了這樣的事情,但它包括一個圖標爲好。這是爲那些正在尋找這個的人準備好的代碼。
在您的佈局中使用
<LinearLayout
android:id="@+id/my_element"
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:layout_height="20dp">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_action_place"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:textColor="@color/black"
android:textSize="12sp"
android:gravity="center_vertical"
android:text=""/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="20dp"
style="@android:style/Widget.ProgressBar.Small"
android:layout_marginRight="5dp" />
</LinearLayout>
這是一個包含了TextView的(在前面只是踢一個額外的圖標)和一個小型紡紗進度一個LinearLayout中。
在活動/片段添加
LinearLayout llMyElement;
在相應的onCreate/onCreateView使用
llMyElement = (LinearLayout) view.findViewById(R.id.my_element);
在的AsyncTask的onPostExecute或任何你想要的過程調用後設置文本setLoadingText(llMyElement, 「Some Result");
並且包含這個輔助函數,該函數將文本設置到您的Activity類或任何合適的地方,例如Util類。
public void setLoadingText(LinearLayout layout, String text)
{
int count = layout.getChildCount();
for(int i = 0; i < count; i++)
{
if(layout.getChildAt(i) instanceof TextView)
((TextView) layout.getChildAt(i)).setText(text);
if(layout.getChildAt(i) instanceof ProgressBar)
layout.getChildAt(i).setVisibility(View.GONE);
}
}
就是這樣..享受!
把它們放在一個FrameLayout
內:
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/my_info_card"
android:gravity="center"
android:layout_gravity="center"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Small"
android:layout_gravity="center"/>
</FrameLayout>
這樣的ProgressBar
出現在TextView
。當然,您可以通過setVisibility()
隱藏ProgressBar。您也可以通過android:layout_gravity
設置每個佈局的重力。在上面的例子中,它看起來是這樣的:
- 1. 顯示進度對話框,直到新的活動加載
- 2. 進度對話框代替TextView,ImageView
- 3. 無法顯示進度對話框
- 4. Android:顯示進度對話框
- 5. 在進度對話框後顯示alertDialog
- 6. 進度對話框沒有顯示
- 7. 顯示OnLocationChanged中的進度對話框
- 8. 無法顯示進度對話框
- 9. 進度對話框不顯示
- 10. 顯示延遲的進度對話框
- 11. 進度對話框顯示不
- 12. 未顯示Android進度對話框
- 13. 進度對話框不顯示在Android?
- 14. 進度對話框將不會顯示
- 15. 進度對話框顯示太晚
- 16. 進度對話框不顯示
- 17. 在webview上顯示進度對話框
- 18. 在DialogFragment中顯示進度對話框
- 19. 進度對話框持續顯示
- 20. Android:進度對話框不顯示
- 21. 安卓進度對話框不顯示
- 22. 進度對話框不顯示
- 23. 在模態對話框頂部顯示進度條對話框
- 24. 如何將進度對話框附加到onClick事件
- 25. 在顯示警告對話框前不顯示進度對話框
- 26. 在警報對話框中顯示textview
- 27. 將進度對話框添加到storefile();
- 28. 如何爲「附加到進程」對話框顯示WCF服務「標題」
- 29. 加載圖片時未顯示進度對話框
- 30. 加載數據時未顯示進度對話框
你所尋找的是進度,而不是progressdialog。 –
絕對,但它並沒有出現在屏幕上並阻止其他組件,我只是想在textview上。 –