2012-06-08 66 views
8

我想在ListView中的项目上设置一个固定的进度。我只能在ListView中看到一个不确定的旋转圈......我做错了什么? (我敢肯定的答案很简单......我只是没有看到它)在listview中的Android进度条总是不确定

对于下列适配器布局XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
    > 
<TextView 
     android:id="@+id/some_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
<ProgressBar 
     android:id="@+id/some_progress" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 

代码:

public class SomeListAdapter extends ArrayAdapter<MyItem> { 

private static class ViewHolder { 
    TextView nameTextView; 
    ProgressBar valueProgressBar; 
} 

public BestChoiceListAdapter(Context context, List<MyItem> items) { 
    super(context, R.layout.list_item, items); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    ViewHolder holder; 
    View view = convertView; 
    if (view == null) { 
     LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     view = vi.inflate(R.layout.list_item, null); 

     holder = new ViewHolder(); 
     holder.nameTextView = (TextView) view.findViewById(R.id.some_text); 
     holder.valueProgressBar = (ProgressBar) view.findViewById(R.id.some_progress); 

     view.setTag(holder); 
    } else { 
     holder = (ViewHolder) convertView.getTag(); 
    } 

    MyItem optionItem = getItem(position); 

    holder.nameTextView.setText(optionItem.getOptionName()); 
    int progress = (int) (optionItem.getOptionValue()); 

    holder.valueProgressBar.setProgress(progress); 

    return view; 
} 
} 

回答

12

最简单的方法是水平形式适用于它:

<ProgressBar 
    android:id="@+id/some_progress" 
    style="@android:style/Widget.ProgressBar.Horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /> 

这将设置所有属性,你会以其他方式需要手动添加到应用确定进度模式。

如果你很好奇,这是一个系统的风格是什么样的,如果你想单独应用属性:

<style name="Widget.ProgressBar.Horizontal"> 
    <item name="android:indeterminateOnly">false</item> 
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> 
    <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> 
    <item name="android:minHeight">20dip</item> 
    <item name="android:maxHeight">20dip</item> 
</style> 

HTH

+0

这样做!我希望这更明显。 –

0

indeterminate mode更改为false!

<ProgressBar 
    android:id="@+id/some_progress" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:indeterminate="false" 
    /> 
+1

我曾经尝试这样做,这不能解决问题无论是。 –

相关问题