編輯:關於 Android 程式設計
本例以點擊按鈕模擬下載進度,展示橫向進度條與環形(次要)進度條兩種效果,下載完成後進度條隱藏。
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar
android:id="@+id/firstBar"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:visibility="gone" />
<ProgressBar
android:id="@+id/secondBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="begin" />
</LinearLayout>
public class ProgressBarTest extends Activity {
private ProgressBar firstBar = null;
private ProgressBar secondBar = null;
private Button myButton = null;
private int i = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
firstBar = (ProgressBar) findViewById(R.id.firstBar);
secondBar = (ProgressBar) findViewById(R.id.secondBar);
myButton = (Button) findViewById(R.id.myButton);
myButton.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
if (i == 0) {
firstBar.setVisibility(View.VISIBLE);
firstBar.setMax(150); // 手動設定最大值,預設為 100
secondBar.setVisibility(View.VISIBLE);
} else if (i < firstBar.getMax()) {
firstBar.setProgress(i);
firstBar.setSecondaryProgress(i + 10);
} else {
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
i = i + 10;
}
}
}
firstBar 為帶進度的橫向進度條,可透過 setProgress 與 setSecondaryProgress 呈現主/次進度;secondBar 為預設的環形忙碌樣式。
Android SQLite 入門:從 adb shell 語法複習到增刪改查 API 實作
開發過程中幾乎一定會碰到資料庫操作。Android 系統內建 SQLite,這是一款遵守 ACID 事特性的輕量級關聯式資料庫管理系統,佔用資源極低,能支援 Window
用百度手機助手連 Chinanet 免費無線上網,不用帳密
百度手機助手已與中國電信達成深度合作,在全國範圍內推出免費 WiFi 服務。只要所在位置有中國電信的 Chinanet 熱點,百度手機助手的使用者就能直接連上,不需要 C
ScrollView 嵌套 ListView 只顯示一項?三種解法與官方建議
ListView 和 GridView 大家都用得很熟了,摯愛新技術的朋友大概已經全面轉向 RecyclerView。但只要還在用 ListView,你就一定遇過這樣的場
Android 實現仿支付寶底部彈窗:DialogFragment 與切換動畫
打開支付寶付款,會從屏幕底部滑上一個面板,讓你確認訂單、選擇付款方式、輸入支付密碼。這一連串交互其實並不複雜,本文動手復刻一遍。 思路拆解 整體分三塊:主界面一個按鈕觸