在学习《第一行代码》的时候没有认真读好代码,因此当我创建了一个新的活动想要设置两个按钮可是检查了许久只有一个按钮出现,排查之后发现原来是主活动的布局除了问题,studio的默认布局是relativeLayout,也就是相对布局,重新定制布局为线式布局即LinearLayou就可以解决问题。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/start_normal_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="start normal acivity"
/>
<Button
android:id="@+id/start_dialog_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="start diaolog activity"
/>
</LinearLayout>