2017-03-18 23 views

回答

0
//Progress bar array. 
final ProgressBar[] bars = new ProgressBar[numTAs+1]; 

//Create and initialize the Progress Bar array. 
for(int i = 0; i < numTAs + 1; i++){ 
    //ProgressBar bar = new ProgressBar(this); 
    int style = android.R.style.Widget_ProgressBar_Horizontal; 
    ProgressBar bar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); 
    bars[i] = bar; 
} 

//Build Adapter 
ArrayAdapter<ProgressBar> adapter = new ArrayAdapter<ProgressBar>(this, R.layout.layout, bars){ 

      @Override 
      public View getView(int position, View convertView, ViewGroup parent){ 

       return bars[position]; 
      } 
     }; 

     ListView list = (ListView) findViewById(R.id.listView); 
     list.setAdapter(adapter); 

    } 
+1

請添加一些關於您自己的答案的描述。 –

1
  1. 在你activity_main.xml中添加的LinearLayout內滾動視圖
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/activity_main" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"/> 
</ScrollView> 
  • MainActivity.java添加此代碼添加progressBar to linearLayout

    int wantedNumber = 5; //get that number from the editText. 
    for (int i = 0; i < wantedNumber; i++) { 
        ProgressBar bar = new ProgressBar(this); 
        bar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 
        LinearLayout linearLayout; 
        linearLayout.addView(bar); 
    } 
    
  • 我只提到了重要的部分讓我知道,如果你遇到任何問題。

    +0

    我似乎無法使滾動條出現 –

    相關問題