2012-04-14 4 views
3

Ich versuche, eine Fortschrittsbalken (nicht progressBar Dialog) nur mit Java zu erstellen.Erstellen Sie eine Fortschrittsbalken ohne XML in Android

Ich kann es nicht funktioniert, alles, was ich bekommen ist:

enter image description here

(ein Bild, das im Kreis Runde halten)

Hier ist mein Code:

b4 = new Button(this); 
    t4 = new ProgressBar(this); 

    b4.setId(4); 
    b4.setText(SensorData.sensorName[4]); 
    b4.setTypeface(null, 1); 
    b4.setTextSize(15); 
    b4.setGravity(Gravity.LEFT); 
    b4.setTextColor(R.color.black); 
    b4.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon, 0); // down 

    // t4.setId(4); 
    t4.setPadding(20, 10, 10, 10); 
    t4.setIndeterminate(false); 
    t4.setProgress(0); 
    t4.setScrollBarStyle(ProgressBar.SCROLLBARS_OUTSIDE_INSET); 
    t4.setMax(100); 
    t4.setVisibility(t4.VISIBLE); 


    sensorsView.addView(b4, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
    sensorsView.addView(t4, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

    b4.setOnClickListener(this); 

Was ich will ist eine horizontale progressBar, weißt du, wie kann ich das tun? Danke.

Antwort

5

ändern diese:

t4 = new ProgressBar(this); 

dazu:

t4 = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); 
+0

Das ist es !! Vielen Dank @Waqas;) –

0

Sie tun können:

t4.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) 
+0

't4' ist eine' ProgressBar', kein 'ProgressDialog', und als solche hat keine' setProgressStyle' Methode. – blahdiblah