Xamarin.android 使用按钮网格创建自定义对话框
我正在尝试添加带有自定义按钮的自定义对话框,这可能吗?如果是,我们怎么做Xamarin.android 使用按钮网格创建自定义对话框,xamarin.android,xamarin,android-gridview,Xamarin.android,Xamarin,Android Gridview,我正在尝试添加带有自定义按钮的自定义对话框,这可能吗?如果是,我们怎么做 这当然是可能的。查看GridView您需要创建一个自定义适配器来加载网格中每个项目的图像和标题 我会这样说的 创建一个简单的类,用于保存有关网格中每个项目的信息。让我们称之为GridItem public class GridItem { public string Title { get; set; } public int ImageResourceId { get; set; } public
这当然是可能的。查看
GridView
您需要创建一个自定义适配器
来加载网格中每个项目的图像和标题
我会这样说的
创建一个简单的类,用于保存有关网格中每个项目的信息。让我们称之为GridItem
public class GridItem
{
public string Title { get; set; }
public int ImageResourceId { get; set; }
public Action ClickAction { get; set; }
}
Title
是图像下的标题,ImageResoruceId
是项目中可绘制的资源ID,即:Resource.Drawable.googleplus
和ClickAction
是单击项目时要执行的操作
现在为网格中的项目创建布局<代码>网格项目.axml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/grid_item_title"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true" />
<ImageView
android:id="@+id/grid_item_image"
android:layout_above="@+id/grid_item_title"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
</RelativeLayout>
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
以及GridView
本身的布局,customgridview对话框.axml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/grid_item_title"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true" />
<ImageView
android:id="@+id/grid_item_image"
android:layout_above="@+id/grid_item_title"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
</RelativeLayout>
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
应该是这样。我无法让它工作,我对Xamarin还很陌生,所以也许我做错了什么。有没有一种方法可以创建这样的解决方案并提供它?不能让它工作是对你经历的一个非常糟糕的描述。请随意编辑您的初始帖子,看看您尝试了什么,哪里出了问题。我没有时间免费创建整个解决方案。Cheesebaron,我完全理解,今天我将尝试更多。然后我会看看是否可以附加代码或其他东西。我只是什么都做不到Cheesebaron,我怎样才能联系到你咨询专案?