代码中setContentView(R.layout.main)作用是设置界面布局,并设置了该Activity的关联视图集根; Button button=(Button)findViewById(R.id.button);从视图集根遍历找到id为button的视图,所以,我们先要进行布局的安排。 在res/layout文件夹下创建main.xml,代码如下,当然随便布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
关于 R.id.
最新推荐文章于 2021-05-28 20:57:15 发布