问题描述:

(Xamarin.Android for Visual Studio 2015)

I'm trying to set up buttons side by side in a gridlayout, spanning evenly across the entire screen. Through searching for answers people say to use layout_columnWeight and layout_rowWeight, but these aren't available due to this:

The 'http://schemas.android.com/apk/res/android:columnWeight' attribute is not declared

but it is. I read that it's not available until API 21, but I have 23 and 24 so that's not the problem.

This is my code for Main.axml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:minWidth="25px"

android:minHeight="25px">

<GridLayout

android:minWidth="25px"

android:minHeight="25px"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:id="@+id/gridLayout1" >

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_rowWeight="1"

android:id="@+id/Button0" />

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_rowWeight="1"

android:id="@+id/Button1" />

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_rowWeight="0"

android:id="@+id/Button2" />

</GridLayout>

</LinearLayout>

EDIT:

I achieved the layout I was going for by changing a couple things.

1) I changed the layout_width in the GridLayout definition to match_parent

2) I took out the layout_width line in each button; I'm assuming this means that the default layout_width is set to "0dp"

I still get the "attribute not declared" warning when using layout_columnWeight, however, it apparently still works.

相关阅读:
Top