0
我有一個2列的TableLayout填充一個片段的整個寬度,但我想要一個特定的項目(一個自定義的進度條)貪婪和佔用儘可能多的寬度,直到表本身的寬度,像這樣:如何強制TableRow中的視圖擴展比表中其餘項的寬度?
_______________________________
|Text1-1|Value1-2 | |
|Text2-1|Value2-2 | |
|Text3-1|Value3-2=============|
的問題是其他行相當短,相比之下,表中保留的區域,我不能讓進度條到超出其指定的列的最寬點。
首先,我試圖把在LinearLayout中的進度條和其相關的文本視圖以2跨度:
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 3-1" />
<LinearLayout
android:layout_span="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value3-2" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100" />
</LinearLayout>
</TableRow>
的LinearLayout中不擴大,超越「列2」的寬度,大概是因爲有沒有「列3」的所有行有2個元素:
_______________________________
|Text1-1|Value1-2 | |
|Text2-1|Value2-2 | |
|Text3-1|Value3-2=| |
然後我刪除的LinearLayout製作進度條了的TableRow的第三個孩子:
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 3-1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value3-2" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100" />
</TableRow>
現在進度條出現在「列3」,但只使用一個任意長度短,儘管有「FILL_PARENT」:
______________________________
|Text1-1|Value1-2| |
|Text2-1|Value2-2| |
|Text3-1|Value3-2|=== |
我怎麼告訴它使用所有由預留的可用寬度桌子?
這是肯定更多的是黑客攻擊的,因爲我不認爲你可以使用TableLayout做到這一點自然的,但你很可能setClipChildren =「假」和setClipToPadding =「false」,然後動態強制ProgressBar的寬度等於列寬度+(column_width * percentage),並且使用左對齊引力和寬度設置爲其父級上的wrap_content ,它可能會延伸到屏幕的邊界之外。但是,這隻適用於父表格擴展的情況 – Guardanis