[Android應用開發]添加了兩個Button後發現只顯示一個
阿新 • • 發佈:2019-01-03
在相關的layout.xml檔案中添加了兩個button後,發現只顯示一個button:
<Button
android:id="@+id/start_normal_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:id="@+id/start_dialog_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button2" />
解決辦法:在頂層新增如下程式碼:
android:orientation="vertical"
原因:android:orientation有兩個屬性,分別是horizontal(水平)和vertical(垂直),如果不設定成vertical,Android預設是horizontal,這時候若設定成match_parent,會導致顯示不全.