我想知道如何格式化按钮,以便它们都显示在屏幕上而不是关闭它?我有一个10x10网格,也希望它们压缩在一起,中间没有间距。我目前正在使用Xamarin在Visual StudiOS中写这篇文章。
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
{
我现在得到的是什么。 http://i.stack.imgur.com/zkBjF.png
答案 0 :(得分:0)
尝试使用如下所示的水平滚动视图,这可能会对您有所帮助:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your content here -->
</HorizontalScrollView>