0
我想知道如何格式化按鈕,以便它們都顯示在屏幕上而不是關閉它?我有一個10x10的網格,也希望它們壓縮在一起,沒有間距。我目前正在用Xamarin在Visual StudiOS中寫這個。在Android中使用按鈕進行網格佈局的問題
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
請具體說明你的問題,你得到的網格佈局,但也有空格按鍵之間,但不這樣做需要他們嗎? – Keshav1234 2015-04-01 06:34:53
是的,我不能得到水平行上的所有10個按鈕。我認爲android:layout_width =「match_parent」可能會這樣做,但似乎沒有。我有一張imgur照片鏈接在我目前正在獲取的文章中。 – 2015-04-01 07:02:15
您是否嘗試過使用水平滾動視圖? – Keshav1234 2015-04-01 07:04:56