2017-04-20 20 views

回答

1

關於您的其他問題Xamarin Forms - How to create custom render to give TableSection the default iOS Footer?,我不確定是要添加頁腳到整個TableView還是要添加到TableView的各個TableSection

如果你想頁腳添加到每個TableSection,我建議只在每個TableSection因爲TableSection可以有多個Cell孩子定製TextCell添加爲頁腳,但如果你想頁腳添加到TableView,可以爲示例代碼像這樣:

public class TableViewWithFooterRenderer : TableViewRenderer 
{ 
    protected override void OnElementChanged(ElementChangedEventArgs<TableView> e) 
    { 
     base.OnElementChanged(e); 
     if (e.NewElement != null) 
     { 
      if (Control != null) 
      { 
       //Add footer to the whole TableView 
       var lv = Control as Android.Widget.ListView; 
       var footerview = ((LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService)) 
        .Inflate(Resource.Layout.TableViewFooter, null, false); 
       lv.AddFooterView(footerview); 
      } 
     } 
    } 
} 

我創建了頁腳視圖,因爲您也可以使用其他視圖。我的頁腳的看法是這樣的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="7dp"> 
    <TextView android:id="@+id/footer" 
      android:text="This is footer" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:gravity="center" 
      android:layout_gravity="center" /> 
</LinearLayout> 

更新:

TableView是在Android平臺rendered as ListView,因爲在Android平臺上沒有本地方法直接添加頁腳的ListView每一個項目,因爲我建議,我們可以手動添加一個定製的TextCellViewCell作爲每個項目的頁腳。正如您從TableSection的源代碼可以看到的那樣,它是一個ObservableCollection對象。

例如:

<TableSection Title="Section 1 Title"> 
    <TextCell Text="TextCell Text" Detail="TextCell Detail"></TextCell> 
    <ViewCell IsEnabled="False"> 
     <Grid> 
      <Label Text="This is footer" /> 
     </Grid> 
    </ViewCell> 
</TableSection> 

我沒有定製的ViewCell風格在這裏,您可以嘗試在它自己的風格。

+0

這就近了。我想要一個頁腳到每個tablesection,而不是整個tableview。看看你的答案,我希望能夠通過膨脹footview並更改文本並將其添加到每個部分。我怎麼能做到這一點?我希望它與iOS版本中的其他問題一樣接近,其中每個節的默認iOS頁腳都有不同的文本。 – SolidSnake4444

+0

@ SolidSnake4444,是的,據我所知,但正如我所說,我們可以添加自定義單元格作爲頁腳的每個表部分,我更新了我的答案,android中沒有本地方法來添加頁腳到android平臺中的每個tablesection。 –

+0

我給它一個鏡頭只顯示在android和uwp視圖單元格,它似乎工作。然而,Android上的最後一個單元格有一個底部邊框,我不知道如何擺脫這一點,但我足夠接近。 – SolidSnake4444

相關問題