編輯:關於Android編程
java.lang.Object;
android.view.View;
android.widget.ProgressBar;
下面我們要學習該類中最常用的方法,主要是 setMax 和 setProgress 等方法。
package com.sweetlover.activity; import com.sweetlover.progressbar.R; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.progress_horizontal); setProgress(progressHorizontal.getProgress() * 100); setSecondaryProgress(progressHorizontal.getSecondaryProgress() * 100); Button button = (Button) findViewById(R.id.increase); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { progressHorizontal.incrementProgressBy(1); // Title progress is in range 0..10000 setProgress(100 * progressHorizontal.getProgress()); } }); button = (Button) findViewById(R.id.decrease); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { progressHorizontal.incrementProgressBy(-1); // Title progress is in range 0..10000 setProgress(100 * progressHorizontal.getProgress()); } }); button = (Button) findViewById(R.id.increase_secondary); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { progressHorizontal.incrementSecondaryProgressBy(1); // Title progress is in range 0..10000 setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress()); } }); button = (Button) findViewById(R.id.decrease_secondary); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { progressHorizontal.incrementSecondaryProgressBy(-1); // Title progress is in range 0..10000 setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress()); } }); } }
<!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%2D%2D%3E--> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="30dp"> <progressbar android:id="@+id/progress_horizontal" style="?android:attr/progressBarStyleHorizontal" android:layout_width="200dip" android:layout_height="wrap_content" android:layout_gravity="center" android:max="100" android:progress="50" android:secondaryprogress="75"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margintop="20dp" android:text="@string/normal"> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_margintop="20dp"><button android:id="@+id/decrease" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/decrease"></button><button android:id="@+id/increase" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/increase"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margintop="20dp" android:text="@string/custom"> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:layout_margintop="20dp"> </linearlayout></textview></button><button android:id="@+id/decrease_secondary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/decrease"></button><button android:id="@+id/increase_secondary" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/increase"></button></linearlayout></textview></progressbar></linearlayout>
<resources> <string name="app_name">ProgressBar</string> <string name="normal">默認進度條</string> <string name="decrease">減少</string> <string name="increase">增加</string> <string name="custom">自定義進度條</string> </resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sweetlover.progressbar" android:versioncode="1" android:versionname="1.0"> <uses-sdk android:minsdkversion="8" android:targetsdkversion="19"> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name="com.sweetlover.activity.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"> <category android:name="android.intent.category.LAUNCHER"> </category></action></intent-filter> </activity> </application> </uses-sdk></manifest>
EditText可以通過layer-list來繪制背景: //用白色來填充裡面
在項目中有一個小功能需要實現,就是對多行文本進行排版布局,每一行的內容又分為兩部分,左邊為標題,右邊為描述,左邊內容長度不確定,右邊的內容需要對齊,如有換行
對我來說,寫自定義view是一個特麻煩但是寫完之後特有成就感的過程。寫完之後我總是喜歡拿給別人看,去炫耀(當然只是在自己熟悉和關系不錯的人群裡),盡管它們看起來會很簡陋。
什麼是View?實現View滑動的方式有哪些?1. 關於View我們需要知道的(1)什麼是View? Android中的View類是所