0
對於ListView
,我想給個別ListView
元素某種進度指示器 - 可以這麼說,我需要一個進度條列表。 但是,每個列表視圖元素都有一些TextView
形式的文本重疊,根本不應受進度欄的影響。將線性佈局背景分解成不同顏色的部分
我認爲圖片可以告訴多字在這種情況下,所以這裏幾乎是我想要的:
我知道我可以添加「sublayouts」個別LinearLayout
S和變化的重編程,這看起來有點像這樣:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@leftSide"
android:background="@color/green"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.8" >
</LinearLayout>
<LinearLayout
android:id="@rightSide"
android:background="@color/red"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2" >
</LinearLayout>
</LinearLayout>
,然後編程方式更改重量爲雙方(已完成和未完成):
float weightLeft = 0.8f;
float weightRight = 1f-weightLeft;
android.widget.LinearLayout.LayoutParams paramsLeft = new android.widget.LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, weightLeft);
LinearLayout left = (LinearLayout) findViewById(R.id.leftside);
left.setLayoutParams(paramsLeft);
android.widget.LinearLayout.LayoutParams paramsRight = new android.widget.LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, weightRight);
LinearLayout right = (LinearLayout) findViewById(R.id.rightside);
left.setLayoutParams(paramsRight);
但是 - 現在的問題是,如何讓textviews坐在父線性佈局上,並忽略子女LinearLayouts
?
我也可以想象有一種方法可以僅使用drawables
來分割背景部分的分佈,但我不知道如何做到這一點,尤其是不能編程。
任何幫助表示讚賞!
真棒!這就像一個魅力!非常感謝 :) – sirio0816