Android debugging (Xamarin) in gridview

I have some buttons that I created using gridview and a custom adapter, but the buttons are surrounded by indentation, which I believe is part of the gridview. I found this thread and tried the solutions, but could not solve the problem. Here is the application image:

enter image description here

XML Code:

<?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="fill_parent"
    android:weightSum="1"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:background="@drawable/background">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.4" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.6">
        <GridView
            android:id="@+id/mainMenuGridview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:numColumns="2"
            android:listSelector="@null"
            android:verticalSpacing="0dp"
            android:horizontalSpacing="0dp" />
    </LinearLayout>
</LinearLayout>

Adapter Code:

class CustomAdapter : BaseAdapter
{
    private readonly Context context;
    private int numRows = 2;

    public CustomAdapter(Context c)
    {
        context = c;
    }

    public override int Count
    {
        get { return buttonTexts.Length; }
    }

    public override Java.Lang.Object GetItem(int position)
    {
        return null;
    }

    public override long GetItemId(int position)
    {
        return 0;
    }

    public override View GetView(int position, View convertView, ViewGroup parent)
    {
        Button button;

        if (convertView == null)
        {
            // if it not recycled, initialize some attributes
            button = new Button(context);
        }
        else
        {
            button = (Button)convertView;
        }

        button.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

        button.SetHeight(Convert.ToInt32((Main_Menu.SCREEN_HEIGHT - Main_Menu.ACTIONBAR_HEIGHT) * 0.6) / numRows);
        button.Text = buttonTexts[position];
        return button;
    }

    private readonly string[] buttonTexts =
    {
        "Button 1",
        "Button 2",
        "Button 3",
        "Button 4"
    };
}

Any help would be greatly appreciated!

+4
source share
2 answers

I do not think that gasket. This seems to be the “space” that all Android buttons are by default part of the background.

To confirm this change, the background of the button is any color:  button.SetBackgroundColor(Android.Graphics.Color.Gray);

+2
source

Xamarin, , :

<StackLayout Padding="0,20,0,0"></StackLayout>

XML Xamarin

0

Source: https://habr.com/ru/post/1679390/


All Articles