C# Android中带按钮的gridlayout存在问题
我想知道如何设置按钮的格式,使它们都显示在屏幕上而不是消失?我有一个10x10的网格,也希望他们压缩在一起,没有间距之间。我现在和Xamarin在视觉工作室写这篇文章C# Android中带按钮的gridlayout存在问题,c#,android,C#,Android,我想知道如何设置按钮的格式,使它们都显示在屏幕上而不是消失?我有一个10x10的网格,也希望他们压缩在一起,没有间距之间。我现在和Xamarin在视觉工作室写这篇文章 protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); GridLayout gl = (GridLayout)FindViewById(Reso
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
GridLayout gl = (GridLayout)FindViewById(Resource.Id.GridLayout1);
// Set our view from the "main" layout resource
Button[] cells = new Button[99];
var i = 0;
foreach (Button b in cells)
{
cells[i] = new Button(this);
gl.AddView(cells[i]);
i++;
}
}}
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/GridLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="10"
android:rowCount="10"
android:orientation="horizontal"
tools:context=".GridXMLActivity" />
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
Namespace App3 {
[Activity(Label = "App3", MainLauncher = true, Icon = "@drawable/icon")]
Public class MainActivity : Activity
{
protectedoverride void OnCreate(捆绑包)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
GridLayout gl=(GridLayout)FindViewById(Resource.Id.GridLayout1);
//从“主”布局资源设置视图
按钮[]单元格=新按钮[99];
var i=0;
foreach(单元格中的按钮b)
{
单元格[i]=新按钮(此按钮);
总账AddView(单元格[i]);
i++;
}
}}
使用制度;
使用Android.App;
使用Android.Content;
使用Android.Runtime;
使用Android.Views;
使用Android.Widget;
使用Android.OS;
名称空间App3{
[活动(Label=“App3”,MainLauncher=true,Icon=“@drawable/Icon”)]
公共课活动:活动
{
我现在得到的。
尝试使用水平滚动视图,如下所示,这可能会帮助您:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your content here -->
</HorizontalScrollView>
请具体说明您的问题,您得到的是网格布局,但按钮之间有空格,但您不需要它们,是吗?是的,我无法在水平行上获得所有10个按钮。我认为android:layout\u width=“match\u parent”也许可以,但似乎不行。我有一张imgur照片链接在我目前得到的帖子中。你试过使用水平滚动视图吗?