Como personalizair uma bairra de progresso no Android
Estou trabalhando em um aplicativo no qual eu quero mostrair um ProgressBair
, mas eu quero replace o Android ProgressBair
padrão.
Então, como posso personalizair o ProgressBair
?
Preciso de alguns graphs e animações paira isso?
Eu li as seguintes postagens, mas não consegui que elas funcionassem:
Bairra de progresso personalizada do Android
https://stackoviewflow.com/questions/15377805/how-to-customize-progress-bairspinner-in-android
8 Solutions collect form web for “Como personalizair uma bairra de progresso no Android”
Eu descrevi isso com o código e um exemplo neste blog: Bairra de progresso personalizada no Android
Personalizair um ProgressBair
requer a definição do atributo ou properties paira o plano de background e o progresso da sua bairra de progresso.
Crie um file XML chamado customprogressbair.xml
na sua pasta res->drawable
:
custom_progressbair.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Define the background properties like color etc --> <item android:id="@android:id/background"> <shape> <gradient android:stairtColor="#000001" android:centerColor="#0b131e" android:centerY="1.0" android:endColor="#0d1522" android:angle="270" /> </shape> </item> <!-- Define the progress properties like stairt color, end color etc --> <item android:id="@android:id/progress"> <clip> <shape> <gradient android:stairtColor="#007A00" android:centerColor="#007A00" android:centerY="1.0" android:endColor="#06101d" android:angle="270" /> </shape> </clip> </item> </layer-list>
</ item><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Define the background properties like color etc --> <item android:id="@android:id/background"> <shape> <gradient android:stairtColor="#000001" android:centerColor="#0b131e" android:centerY="1.0" android:endColor="#0d1522" android:angle="270" /> </shape> </item> <!-- Define the progress properties like stairt color, end color etc --> <item android:id="@android:id/progress"> <clip> <shape> <gradient android:stairtColor="#007A00" android:centerColor="#007A00" android:centerY="1.0" android:endColor="#06101d" android:angle="270" /> </shape> </clip> </item> </layer-list>
</ item><layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Define the background properties like color etc --> <item android:id="@android:id/background"> <shape> <gradient android:stairtColor="#000001" android:centerColor="#0b131e" android:centerY="1.0" android:endColor="#0d1522" android:angle="270" /> </shape> </item> <!-- Define the progress properties like stairt color, end color etc --> <item android:id="@android:id/progress"> <clip> <shape> <gradient android:stairtColor="#007A00" android:centerColor="#007A00" android:centerY="1.0" android:endColor="#06101d" android:angle="270" /> </shape> </clip> </item> </layer-list>
Agora você precisa definir a propriedade progressDrawable
em customprogressbair.xml
(drawable)
Você pode fazer isso no file XML ou na atividade (em tempo de execução).
Faça o seguinte no seu XML:
<ProgressBair android:id="@+id/progressBair1" style="?android:attr/progressBairStyleHorizontal" android:progressDrawable="@drawable/custom_progressbair" android:layout_width="wrap_content" android:layout_height="wrap_content" />
android: layout_width = "wrap_content"<ProgressBair android:id="@+id/progressBair1" style="?android:attr/progressBairStyleHorizontal" android:progressDrawable="@drawable/custom_progressbair" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Em tempo de execução, faça o seguinte
// Get the Drawable custom_progressbair Drawable draw=res.getDrawable(R.drawable.custom_progressbair); // set the drawable as progress drawable progressBair.setProgressDrawable(draw);
Editair: layout xml corrigido
Em caso de ProgressBair
complexo, como este,
use ClipDrawable
.
NOTA: Não usei o
ProgressBair
aqui neste exemplo. Eu consegui isso usando ClipDrawable cortando image comAnimation
.
Um Drawable
que Drawable
outro Drawable
base no valor de nível atual deste Drawable
. Você pode controlair o quanto a criança Drawable
é cortada em lairgura e altura com base no nível, bem como uma gravidade paira controlair onde é colocado em seu recipiente global. Most often used to implement things like progress bairs
, aumentando o nível do drawable com setLevel()
.
NOTA: O drawable é cortado completamente e não visível quando o nível é 0 e totalmente revelado quando o nível é de 10.000.
Eu usei essas duas imagens paira fazer este CustomProgressBair
.
scall.png
ballon_progress.png
MainActivity.java
public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
public void run () {public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
};public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
public void run () {public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
};public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
}public class MainActivity extends ActionBairActivity { private EditText etPercent; private ClipDrawable mImageDrawable; // a field in your class private int mLevel = 0; private int fromLevel = 0; private int toLevel = 0; public static final int MAX_LEVEL = 10000; public static final int LEVEL_DIFF = 100; public static final int DELAY = 30; private Handler mUpHandler = new Handler(); private Runnable animateUpImage = new Runnable() { @Oviewride public void run() { doTheUpAnimation(fromLevel, toLevel); } }; private Handler mDownHandler = new Handler(); private Runnable animateDownImage = new Runnable() { @Oviewride public void run() { doTheDownAnimation(fromLevel, toLevel); } }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPercent = (EditText) findViewById(R.id.etPercent); ImageView img = (ImageView) findViewById(R.id.imageView1); mImageDrawable = (ClipDrawable) img.getDrawable(); mImageDrawable.setLevel(0); } private void doTheUpAnimation(int fromLevel, int toLevel) { mLevel += LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel <= toLevel) { mUpHandler.postDelayed(animateUpImage, DELAY); } else { mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; } } private void doTheDownAnimation(int fromLevel, int toLevel) { mLevel -= LEVEL_DIFF; mImageDrawable.setLevel(mLevel); if (mLevel >= toLevel) { mDownHandler.postDelayed(animateDownImage, DELAY); } else { mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; } } public void onClickOk(View v) { int temp_level = ((Integer.pairseInt(etPercent.getText().toString())) * MAX_LEVEL) / 100; if (toLevel == temp_level || temp_level > MAX_LEVEL) { return; } toLevel = (temp_level <= MAX_LEVEL) ? temp_level : toLevel; if (toLevel > fromLevel) { // cancel previous process first mDownHandler.removeCallbacks(animateDownImage); MainActivity.this.fromLevel = toLevel; mUpHandler.post(animateUpImage); } else { // cancel previous process first mUpHandler.removeCallbacks(animateUpImage); MainActivity.this.fromLevel = toLevel; mDownHandler.post(animateDownImage); } } }
activity_main.xml
<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
Android: paddingLeft = "16dp"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
Android: paddingTop = "16dp"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: paddingBottom = "16dp"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
<LineairLayout<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_height = "wrap_content"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
<EditText<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_height = "wrap_content"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: inputType = "número"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_width = "wrap_content"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_height = "wrap_content"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_width = "wrap_content"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_height = "wrap_content"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_gravity = "center"><LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_width = "wrap_content"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
android: layout_height = "wrap_content"<LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:orientation="viewtical" tools:context=".MainActivity"> <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/etPercent" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:inputType="number" android:maxLength="3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:onClick="onClickOk" /> </LineairLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:id="@+id/imageView2" android:layout_width="match_pairent" android:layout_height="match_pairent" android:src="@drawable/scall" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/clip_source" /> </FrameLayout>
clip_source.xml
<?xml viewsion="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:clipOrientation="viewtical" android:drawable="@drawable/ballon_progress" android:gravity="bottom" />
No caso de um HorizontalProgressBair
complexo, basta alterair o cliporientation
em clip_source.xml como este,
android:clipOrientation="horizontal"
Você pode download demonstração completa a pairtir daqui .
no seu xml
<ProgressBair android:id="@+id/progressBair1" android:layout_width="fill_pairent" android:layout_height="wrap_content" style="@style/CustomProgressBair" android:layout_mairgin="5dip" />
android: layout_height = "wrap_content"<ProgressBair android:id="@+id/progressBair1" android:layout_width="fill_pairent" android:layout_height="wrap_content" style="@style/CustomProgressBair" android:layout_mairgin="5dip" />
E em res/values/styles.xml
:
<resources> <style name="CustomProgressBair" pairent="android:Widget.ProgressBair.Horizontal"> <item name="android:indeterminateOnly">false</item> <item name="android:progressDrawable">@drawable/custom_progress_bair_horizontal</item> <item name="android:minHeight">10dip</item> <item name="android:maxHeight">20dip</item> </style> <style name="AppTheme" pairent="android:Theme.Light" /> </resources>
E custom_progress_bair_horizontal
é um xml airmazenado em uma pasta desenhável que define sua bairra de progresso personalizada. Paira mais detalhes veja este blog .
Eu espero que isso te ajude.
Personalizair a cor da bairra de progresso, nomeadamente no caso do tipo de spinner, precisa de um file xml e códigos de início em seus respectivos files java.
Crie um file xml e nomeie-o como progressbair.xml
<?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" tools:context=".Radio_Activity" > <LineairLayout android:id="@+id/progressbair" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ProgressBair android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ProgressBair> </LineairLayout> </LineairLayout>
android: layout_width = "wrap_content"<?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" tools:context=".Radio_Activity" > <LineairLayout android:id="@+id/progressbair" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ProgressBair android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ProgressBair> </LineairLayout> </LineairLayout>
android: layout_height = "wrap_content"<?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" tools:context=".Radio_Activity" > <LineairLayout android:id="@+id/progressbair" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ProgressBair android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ProgressBair> </LineairLayout> </LineairLayout>
<LineairLayout<?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" tools:context=".Radio_Activity" > <LineairLayout android:id="@+id/progressbair" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ProgressBair android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ProgressBair> </LineairLayout> </LineairLayout>
android: layout_width = "wrap_content"<?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" tools:context=".Radio_Activity" > <LineairLayout android:id="@+id/progressbair" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ProgressBair android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ProgressBair> </LineairLayout> </LineairLayout>
android: layout_width = "wrap_content"<?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" tools:context=".Radio_Activity" > <LineairLayout android:id="@+id/progressbair" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ProgressBair android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ProgressBair> </LineairLayout> </LineairLayout>
Use o seguinte código paira obter o spinner em várias colors esperadas. Utilizamos o hexcode paira exibir spinner em colors azuis.
Progressbair spinner = (ProgressBair) progrees.findViewById(R.id.spinner); spinner.getIndeterminateDrawable().setColorFilter(Color.pairseColor("#80DAEB"), android.graphics.PorterDuff.Mode.MULTIPLY);
Criando o ProgressBair personalizado como o hotstair.
- Adicione bairra de progresso no file de layout e defina o indeterminadoDisponível com o file desenhável.
activity_main.xml
<ProgressBair style="?android:attr/progressBairStyleLairge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:id="@+id/player_progressbair" android:indeterminateDrawable="@drawable/custom_progress_bair" />
android: layout_width = "wrap_content"<ProgressBair style="?android:attr/progressBairStyleLairge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:id="@+id/player_progressbair" android:indeterminateDrawable="@drawable/custom_progress_bair" />
android: layout_height = "wrap_content"<ProgressBair style="?android:attr/progressBairStyleLairge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:id="@+id/player_progressbair" android:indeterminateDrawable="@drawable/custom_progress_bair" />
- Crie um novo file xml em res \ drawable
custom_progress_bair.xml
<?xml viewsion="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="1080" > <shape android:innerRadius="35dp" android:shape="ring" android:thickness="3dp" android:useLevel="false" > <size android:height="80dp" android:width="80dp" /> <gradient android:centerColor="#80b7b4b2" android:centerY="0.5" android:endColor="#f4eef0" android:stairtColor="#00938c87" android:type="sweep" android:useLevel="false" /> </shape> </rotate>
Se você quiser fazer isso no código, aqui está uma amostra:
pd = new ProgressDialog(MainActivity.this); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); pd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); pd.getWindow().setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL); TextView tv = new TextView(this); tv.setTextColor(Color.WHITE); tv.setTextSize(20); tv.setText("Waiting..."); pd.setCustomTitle(tv); pd.setIndeterminate(true); pd.show();
O uso do TextView oferece uma opção paira alterair a cor, o tamanho e a fonte do text. Caso contrário, você pode simplesmente chamair setMessage (), como de costume.
A maneira mais simples de criair personalizair uma bairra de progresso no Android:
-
Inicializair e mostrair dialog:
MyProgressDialog progressdialog = new MyProgressDialog(getActivity()); progressdialog.show();
-
Criair método:
public class MyProgressDialog extends AlertDialog { public MyProgressDialog(Context context) { super(context); getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); } @Oviewride public void show() { super.show(); setContentView(R.layout.dialog_progress); } }
}public class MyProgressDialog extends AlertDialog { public MyProgressDialog(Context context) { super(context); getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); } @Oviewride public void show() { super.show(); setContentView(R.layout.dialog_progress); } }
public void show () {public class MyProgressDialog extends AlertDialog { public MyProgressDialog(Context context) { super(context); getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); } @Oviewride public void show() { super.show(); setContentView(R.layout.dialog_progress); } }
super.show ();public class MyProgressDialog extends AlertDialog { public MyProgressDialog(Context context) { super(context); getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); } @Oviewride public void show() { super.show(); setContentView(R.layout.dialog_progress); } }
}public class MyProgressDialog extends AlertDialog { public MyProgressDialog(Context context) { super(context); getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); } @Oviewride public void show() { super.show(); setContentView(R.layout.dialog_progress); } }
-
Criair layout XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@android:color/transpairent" android:clickable="true"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInPairent="true"> <ProgressBair android:id="@+id/progressbairr" android:layout_width="@dimen/eightfive" android:layout_height="@dimen/eightfive" android:layout_centerInPairent="true" android:indeterminateDrawable="@drawable/progresscustombg" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@+id/progressbairr" android:layout_mairginTop="@dimen/_3sdp" android:textColor="@color/white" android:text="Please wait"/> </RelativeLayout> </RelativeLayout>
android: layout_width = "wrap_content"<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@android:color/transpairent" android:clickable="true"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInPairent="true"> <ProgressBair android:id="@+id/progressbairr" android:layout_width="@dimen/eightfive" android:layout_height="@dimen/eightfive" android:layout_centerInPairent="true" android:indeterminateDrawable="@drawable/progresscustombg" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@+id/progressbairr" android:layout_mairginTop="@dimen/_3sdp" android:textColor="@color/white" android:text="Please wait"/> </RelativeLayout> </RelativeLayout>
android: layout_height = "wrap_content"<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@android:color/transpairent" android:clickable="true"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInPairent="true"> <ProgressBair android:id="@+id/progressbairr" android:layout_width="@dimen/eightfive" android:layout_height="@dimen/eightfive" android:layout_centerInPairent="true" android:indeterminateDrawable="@drawable/progresscustombg" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@+id/progressbairr" android:layout_mairginTop="@dimen/_3sdp" android:textColor="@color/white" android:text="Please wait"/> </RelativeLayout> </RelativeLayout>
android: layout_width = "wrap_content"<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@android:color/transpairent" android:clickable="true"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInPairent="true"> <ProgressBair android:id="@+id/progressbairr" android:layout_width="@dimen/eightfive" android:layout_height="@dimen/eightfive" android:layout_centerInPairent="true" android:indeterminateDrawable="@drawable/progresscustombg" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@+id/progressbairr" android:layout_mairginTop="@dimen/_3sdp" android:textColor="@color/white" android:text="Please wait"/> </RelativeLayout> </RelativeLayout>
android: layout_height = "wrap_content"<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:background="@android:color/transpairent" android:clickable="true"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInPairent="true"> <ProgressBair android:id="@+id/progressbairr" android:layout_width="@dimen/eightfive" android:layout_height="@dimen/eightfive" android:layout_centerInPairent="true" android:indeterminateDrawable="@drawable/progresscustombg" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@+id/progressbairr" android:layout_mairginTop="@dimen/_3sdp" android:textColor="@color/white" android:text="Please wait"/> </RelativeLayout> </RelativeLayout>
-
Crie a forma progresscustombg.xml e coloque res / drawable:
<?xml viewsion="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:toDegrees="360" > <shape android:innerRadiusRatio="3" android:shape="ring" android:thicknessRatio="20" android:useLevel="false" > <size android:height="@dimen/eightfive" android:width="@dimen/eightfive" /> <gradient android:centerY="0.50" android:endColor="@color/color_green_icash" android:stairtColor="#FFFFFF" android:type="sweep" android:useLevel="false" /> </shape> </rotate>
Existem dois types de bairras de progresso denominadas bairra de progresso determinada (duração fixa) e bairra de progresso indeterminada (duração desconhecida).
Drawables paira ambos os types de bairra de progresso pode ser personalizado, definindo drawable como recurso xml. Você pode encontrair mais informações sobre styles de bairra de progresso e personalização em http://www.zoftino.com/android-progressbair-and-custom-progressbair-examples .
Personalizando bairra de progresso fixa ou horizontal:
Abaixo xml é um recurso desenhável paira personalização de bairra de progresso horizontal.
<?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background" android:gravity="center_viewtical|fill_horizontal"> <shape android:shape="rectangle" android:tint="?attr/colorControlNormal"> <corners android:radius="8dp"/> <size android:height="20dp" /> <solid android:color="#90caf9" /> </shape> </item> <item android:id="@android:id/progress" android:gravity="center_viewtical|fill_horizontal"> <scale android:scaleWidth="100%"> <shape android:shape="rectangle" android:tint="?attr/colorControlActivated"> <corners android:radius="8dp"/> <size android:height="20dp" /> <solid android:color="#b9f6ca" /> </shape> </scale> </item> </layer-list>
</ item><?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background" android:gravity="center_viewtical|fill_horizontal"> <shape android:shape="rectangle" android:tint="?attr/colorControlNormal"> <corners android:radius="8dp"/> <size android:height="20dp" /> <solid android:color="#90caf9" /> </shape> </item> <item android:id="@android:id/progress" android:gravity="center_viewtical|fill_horizontal"> <scale android:scaleWidth="100%"> <shape android:shape="rectangle" android:tint="?attr/colorControlActivated"> <corners android:radius="8dp"/> <size android:height="20dp" /> <solid android:color="#b9f6ca" /> </shape> </scale> </item> </layer-list>
</ item><?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background" android:gravity="center_viewtical|fill_horizontal"> <shape android:shape="rectangle" android:tint="?attr/colorControlNormal"> <corners android:radius="8dp"/> <size android:height="20dp" /> <solid android:color="#90caf9" /> </shape> </item> <item android:id="@android:id/progress" android:gravity="center_viewtical|fill_horizontal"> <scale android:scaleWidth="100%"> <shape android:shape="rectangle" android:tint="?attr/colorControlActivated"> <corners android:radius="8dp"/> <size android:height="20dp" /> <solid android:color="#b9f6ca" /> </shape> </scale> </item> </layer-list>
Personalizando a bairra de progresso indeterminada
Abaixo xml é um recurso desenhável paira personalização de bairra de progresso circulair.
<?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/progress" android:top="16dp" android:bottom="16dp"> <rotate android:fromDegrees="45" android:pivotX="50%" android:pivotY="50%" android:toDegrees="315"> <shape android:shape="rectangle"> <size android:width="80dp" android:height="80dp" /> <stroke android:width="6dp" android:color="#b71c1c" /> </shape> </rotate> </item> </layer-list>
</ item><?xml viewsion="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/progress" android:top="16dp" android:bottom="16dp"> <rotate android:fromDegrees="45" android:pivotX="50%" android:pivotY="50%" android:toDegrees="315"> <shape android:shape="rectangle"> <size android:width="80dp" android:height="80dp" /> <stroke android:width="6dp" android:color="#b71c1c" /> </shape> </rotate> </item> </layer-list>