程在Xamarin通过tablerow添加到TableLayou

程在Xamarin通过tablerow添加到TableLayou

本文介绍了如何编程在Xamarin通过tablerow添加到TableLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有我的布局,其中包含我的布局定义这里TableLayout

So I have my layout that contains a TableLayout defined in my layout here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/defaultBackground_vert"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainLayout">
<TableLayout
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/table">
</TableLayout>
</LinearLayout>

和我访问它在我的codebehind,并试图将按钮添加到表行和tablerow的添加到表:

And I am accessing it in my codebehind and trying to add a button to a table row and add that tablerow to the table:

private TableLayout _table
private Button _button
.
.
.
_table = FindViewById<TableLayout>(Resource.Id.table);
_button = new Button(this){Text = "<"};
_button = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
var tableRow = new TableRow(this);
tableRow.AddView(_button, 0);
_table.AddView(tableRow, 0);

问题是,tablerow的显示不出来,当我运行我的应用程序。

The problem is that the tableRow does not show up when I run my application.

推荐答案

您需要使用TableRow.Layoutparams的按钮..试试这个code。

You need to use TableRow.Layoutparams for the buttons.. Try this code.

    TableLayout _table = (TableLayout) findViewById(R.id.table);

    LayoutParams layoutParams = new TableRow.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    TableRow tableRow = new TableRow(this);

    Button _button = new Button(this);
    _button.setText(">>");
    _button.setLayoutParams(layoutParams);

    tableRow.addView(_button, 0);
    _table.addView(tableRow, 0);

这篇关于如何编程在Xamarin通过tablerow添加到TableLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:38