如何在自定义的一个view中加一个button!! Button就是一个View你应该是没有办法在View里面再加一个Button的建议你用ViewGroup 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼上正解。楼主也可以自己判断点击的区域来实现button的效果。 <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Type here:"/> <EditText android:id="@+id/entry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" android:layout_below="@id/label"/> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/entry" android:layout_alignParentRight="true" android:layout_marginLeft="10dip" android:text="OK" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/ok" android:layout_alignTop="@id/ok" android:text="Cancel" /></RelativeLayout>Button继承自View,但它不能直接被加在View中,但可以被加入ViewGruop; 这个RelativeLayout就是继承自ViewGroup,所以可以被加入! Android手机Root后怎么修改系统的自启动项 android选项菜单 android锁屏后broadcastreceiver不工作 在手机屏幕锁屏的情况下调用NFC服务 关于安卓 Android 检测Temperature,过高或者过低则进行关机,如何实现? android客户端怎样连接服务器 关于Android Studio中创建和访问数据库SQLite的基本概念 assets资源文件太大,调试的时候打包下载太慢怎么解决 布局中控件显示不出来,怎么处理? 请教 android程序中怎样判断列表中哪一行是被选中的 Android设计界面主要会涉及到哪些技术?
楼上正解。楼主也可以自己判断点击的区域来实现button的效果。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>Button继承自View,但它不能直接被加在View中,但可以被加入ViewGruop;
这个RelativeLayout就是继承自ViewGroup,所以可以被加入!