我希望列表项的背景像进度条一样工作.例如,在tTorrent文件列表中:
现在就是这样做的:我使用了relativelayout和两个线性输出.一个有textview,另一个有两个视图作为进度条.使用视图的权重更改"进度",这是在getView方法中动态设置的.然后将带有textview的linearlayout放在前面.这是代码:
布局:
<LinearLayout
android:padding="5dp"
android:id="@+id/catStatsRowLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- textviews on the front -->
...
</LinearLayout>
<!-- views which work as progress bar -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/catStatsRowLay"
android:layout_alignLeft="@id/catStatsRowLay"
android:layout_alignRight="@id/catStatsRowLay"
android:layout_alignTop="@id/catStatsRowLay"
android:layout_below="@id/catStatsRowLay"
android:layoutDirection="rtl"
android:orientation="horizontal" >
<View
android:id="@+id/catStatsRowBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".70"
android:background="#cc550000" />
<View
android:id="@+id/catStatsRowBar2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".30"
android:background="@android:color/transparent" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
和getView方法:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.categories_stats_list_row,
parent, false);
//filling textviews
...
//getting bars …Run Code Online (Sandbox Code Playgroud)