Forum Xamarin.Android

How to set height and width on TableRow programmatically

Hi!
I have simple table (5 columns and few rows). I want to fill to each cell my "Custom Button" (another Layout), and I have a problem with size cells when "Custom button" is inside. I try to change it by LayoutParameters but doesn't work. I want to get a square but I received a rectangle.

I have to use layout as a button because I want to button with few textview (current I have two textView)

My "CustomButton" BigButton.axml:

<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:orientation="vertical"
    p1:layout_width="@dimen/button_size"
    p1:layout_height="@dimen/button_size"
    p1:id="@+id/linearLayoutMainContainer"
    p1:background="@color/transparent">
    <RelativeLayout
        p1:minWidth="25px"
        p1:minHeight="25px"
        p1:layout_width="match_parent"
        p1:layout_height="wrap_content"
        p1:id="@+id/relativeLayout1"
        p1:layout_margin="2dp">
        <TextView
            p1:text="AB"
            p1:textAppearance="?android:attr/textAppearanceMedium"
            p1:layout_width="match_parent"
            p1:layout_height="match_parent"
            p1:id="@+id/textViewCurrentFunction"
            p1:gravity="center"
            p1:textColor="@android:color/white"
            p1:background="@android:color/holo_blue_dark" />
        <TextView
            p1:text="A"
            p1:layout_width="match_parent"
            p1:layout_height="wrap_content"
            p1:id="@+id/textViewRightFunction"
            p1:layout_gravity="center"
            p1:gravity="right"
            p1:textColor="@android:color/holo_orange_dark"
            p1:textSize="12dp"
            p1:layout_margin="2dp" />
    </RelativeLayout>
</LinearLayout>

My C# code:

 // The main table  
 TableLayout mainTable = FindViewById<TableLayout>(Resource.Id.tableMainTable);  // Empty table from main view

 //test row
TableRow oneTableRow = new TableRow(this);

 // button size
TableRow.LayoutParams numberButtonSize = new TableRow.LayoutParams(Resource.Dimension.button_size, Resource.Dimension.button_size);

numberButtonSize.Height = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, Resource.Dimension.button_size, Resources.DisplayMetrics);
oneTableRow.SetBackgroundColor(Android.Graphics.Color.Beige);
oneTableRow.LayoutParameters = numberButtonSize; // <- It doesn't work :(
LayoutInflater inflater = LayoutInflater.From(this);

View plusMinusButton = inflater.Inflate(Resource.Layout.BigButton, null);
TextView tvCurrentFinction = plusMinusButton.FindViewById<TextView>(Resource.Id.textViewCurrentFunction);
tvCurrentFinction.Text = GetString(Resource.String.plus_minus);
TextView tvRightFunction = plusMinusButton.FindViewById<TextView>(Resource.Id.textViewRightFunction);
tvRightFunction.Text = "f";
oneTableRow.AddView(plusMinusButton);
Sign In or Register to comment.