xamarin - 我可以有一个完整的线性布局的点击事件吗
问题描述
我有一个线性布局和布局内的一些按钮。当单击线性布局时,它应该导航到新的 page1,当单击按钮时,它应该导航到 page2。
解决方案
如果是这样,是的,您可以为您的LinearLayout
.There 添加点击事件。这是我的代码。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/my_ll">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click"
android:id="@+id/button1"
/>
</LinearLayout>
这是背景代码。为线性布局和按钮添加不同的点击监听器。
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
LinearLayout my_ll = FindViewById<LinearLayout>(Resource.Id.my_ll);
Button button1 = FindViewById<Button>(Resource.Id.button1);
my_ll.Click += My_ll_Click;
button1.Click += Button1_Click;
}
private void Button1_Click(object sender, System.EventArgs e)
{
Intent intent = new Intent(this, typeof(Activity2));
StartActivity(intent);
}
private void My_ll_Click(object sender, System.EventArgs e)
{
Intent intent = new Intent(this,typeof(Activity1));
StartActivity(intent);
}
}
推荐阅读
- libgdx - ClickListener 仅适用于 Table Libgdx 中的元素
- python - Python 3.6:在 AWS Ubuntu 上写入文件时忽略新行命令“/n”
- sql - 按子句顺序使用列名时出现歧义错误
- jquery - 动画 - Css 中的滚动顶部
- javascript - 在多个 Vue 应用程序之间共享路由的最佳实践是什么?
- python - 比较裁剪的图像 python opencv
- laravel - 如何在单元测试 Laravel 中获取电子邮件验证链接
- php - 从链接 PHP 生成 PDF
- java - 在类型安全配置中访问完全解析的配置
- r - 散点图中每个因素的统计摘要 ggplot2:fun.x、fun_y 组合怎么样?