2012-06-03 37 views
0

下面的圖片是我正在尋找的Listview行。其種類清單列表。帶有一些非標準列的Android Listview

enter image description here

問:

如何繪製/創建這樣一個列表視圖排 其中

1)第一列沒有HORIZ的。或垂直。分線器。

2)第二列是一種有兩個horz的盒子。和垂直分離線。

第二列和第三列之間有空格。

3)第三列是標準列表視圖行,其中包含文本和小圖標。

如何結合所有3使這個jazy排? :)

我知道如何使第三列單獨列表視圖;與文本和圖像。但列間距和垂直線是我不知道的。

謝謝你的任何建議

雅各

+0

看看我的帖子,我已經解決了這個問題http://stackoverflow.com/questions/10811192/how-to-add-header-in-listview-at-specific-location-and-create - 自定義查看li/10811630#10811630 –

+0

謝謝;我會看看它。 – user702426

回答

0

我一直在使用TableLayout和取得的TableRow類似的東西。它允許您使用XML創建「行模板」,然後按照您希望的順序執行它們。

說你有你的活動使用的佈局main.xml中:

setContentView(R.layout.main); 

然後,當你需要它,你會膨脹的每一行的模板:

 LayoutInflater myInflate = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    row1 = (TableRow) myInflate.inflate(R.layout.matchesoverviewlistitem, null); 

    // Here you can do anything you want with the table row elements 
    tv = (TextView)row1.findViewById(R.id.matchesOverLabel); 
    tv.setText("MyText"); 

    row1.setTag(n); 
    row1.setOnClickListener(seriesListener); 

    // Finally add the table row to the tableLayout 
    myTable.addView(row1,new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); 

這爲我工作得很好時使用多行不同的佈局。

+0

感謝您的迴應;欣賞它;我會採取兩個迴應。 – user702426

2

創建ListView的行佈局所示的佈局並不太棘手。我會在路上幫你一下。請注意,您可能需要進行一些改進,例如,不要硬編碼「方塊」的大小,而是在您的不同屏幕密度/大小存儲桶中提供dimens.xml

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" 
    android:gravity="center_vertical"> 

    <View android:layout_width="30dp" android:layout_height="30dp" 
     android:layout_margin="5dp" android:background="@drawable/border_color_red" /> 

    <TextView android:layout_width="?android:attr/listPreferredItemHeight" 
     android:layout_height="?android:attr/listPreferredItemHeight" 
     android:background="@drawable/border" android:gravity="center" 
     android:text="QTY" android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <RelativeLayout android:layout_width="0dp" 
     android:layout_height="?android:attr/listPreferredItemHeight" 
     android:layout_marginLeft="5dp" android:layout_marginRight="5dp" 
     android:layout_weight="1" android:background="@drawable/border" 
     android:gravity="center_vertical" android:padding="5dp"> 

     <TextView android:id="@android:id/text1" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:layout_centerVertical="true" android:layout_toLeftOf="@+id/star" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <CheckBox android:id="@+id/star" style="?android:attr/starStyle" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:layout_centerVertical="true" android:layout_toLeftOf="@+id/box_right" 
      android:text=" " /> 

     <View android:id="@+id/box_right" android:layout_width="30dp" 
      android:layout_height="30dp" android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" android:layout_margin="5dp" 
      android:background="@drawable/border_color_red" /> 
    </RelativeLayout> 

</LinearLayout> 

ListView將需要隱藏的除法:

<ListView android:id="@android:id/list" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:divider="@null"> 
     <!-- Preview: [email protected]/list_item_layout --> 
    </ListView> 

邊框使用的是簡單的ShapeDrawable補充說:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <stroke android:height="1dp" android:width="1dp" android:color="#000" /> 
    <solid android:color="@android:color/transparent" /> 
</shape> 

更改solid色營造出不同的填充顏色(如爲正方形)。

結果將看起來有點像這樣:

list item layout

最大的缺點是,有沒有真正擺脫「雙」分隔插圖中的不同行的一個簡單的方法。如果真的困擾你,那麼肯定有一些方法可以解決它們(例如,爲適配器中的第一個和最後一個項目填充不同的佈局,或者將第一個和最後一個項目添加爲頁眉和頁腳,或者將這些行分解爲單獨的視圖,你可以切換,等等......)。

我沒有在ImageView中加入,因爲那樣會很明顯。將它放在與'item'TextView相同的位置,並根據您想要顯示文本還是圖像來在兩者之間切換。

我假設你能夠爲佈局想出匹配的Adapter(和'ViewHolder'/'RowWrapper')。

如果還有什麼不清楚,請刪除一行。 :)

+0

謝謝你的迴應;非常感謝。我只知道SimpleAdapter類。你可以請建議一個Android適配器的例子,我應該看看上面的任務。此外,上面的明星複選框是可點擊的。 RED查看框可以點擊嗎?再次感謝。 – user702426

+0

例子很普遍,[這裏看起來很好](http://goo.gl/2qXTy)。總而言之,您需要將數據存儲在列表中的簡單Java對象中,然後將其傳遞給'Adapter'。關於這些方塊:根據你所追求的行爲,你可以爲這兩種狀態(開/關)設置一個「CheckBox」或「ToggleButton」。如果你需要更復雜的行爲,你可能會自己創建/擴展一些東西。如果您不希望小部件可點擊,只需將該屬性標誌設置爲false即可。 –