gpt4 book ai didi

ListView 中的 Android 进度条始终不确定

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:21 25 4
gpt4 key购买 nike

我正在尝试为 ListView 中的项目设置固定进度。我只在 ListView 中看到一个不确定的旋转圆圈……我做错了什么? (我确定答案很简单......我只是没有看到)

对于以下适配器布局 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;
}
}

最佳答案

最简单的方法是对其应用水平样式:

<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

关于 ListView 中的 Android 进度条始终不确定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10955204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com