安卓之使用标签创建按钮

安卓很灵活因为他的内核是linux的,又有C++的库,应用层还是java完成。导致实现同一个功能可以由java,html,C#,C++4种方法实现。这次分享标签实现。
首先进入项目找到res(resource资源)文件夹,在这个文件夹里面找到layout(布局)文件夹,在这里我们可以看到你的活动界面的主xml。点击这个xml进入代码界面在布局标签里面(默认RelativeLayout或者LinearLayout)添加:

 <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:onClick="画画"
        android:text="画画" />
 <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/textView1"
        android:layout_below="@+id/button1"
        android:onClick="清除"
        android:text="清除" />

是不是很类似HTML语言?懂HTML的就不多做解释了。
注意:
layout_width表示布局宽度
fill_parent表示填充满父窗体
android:onClick为点击事件
预览结果如下(有警告不管他,能正常使用就行):
在这里插入图片描述

发布了67 篇原创文章 · 获赞 1 · 访问量 7241

猜你喜欢

转载自blog.csdn.net/GodGump/article/details/104527100