我必須製作一個迷你項目,一個計算器。所以我開始研究這個。
當我嘗試將某些按鈕置於其位置(按數字順序)時,出現問題。如何在圖形xml設計屏幕中的Android Studio中移動對象?
例如,我決定每行需要3個按鈕。
當我嘗試移動上排時,所有按鈕都會丟失其順序。
是否有自動排序選項以禁用?
我必須製作一個迷你項目,一個計算器。所以我開始研究這個。
當我嘗試將某些按鈕置於其位置(按數字順序)時,出現問題。如何在圖形xml設計屏幕中的Android Studio中移動對象?
例如,我決定每行需要3個按鈕。
當我嘗試移動上排時,所有按鈕都會丟失其順序。
是否有自動排序選項以禁用?
這是簡單的只是將它們放置在LinearLayout中的水平可以在所有設備上工作,如:
<LinearLayout orientation="vertical" layout_width="wrap_content">
<LinearLayout orientation="horizontal" layout_width="wrap_content">
<Button>One</Button>
<Button>Two</Button>
<Button>Three</Button>
</LinearLayout>
</LinearLayout>
使用盡可能多的按鈕,只要你喜歡。
嵌套LinearLayouts?網格或表格佈局會更好 –
有很多方法可以做到這一點,我喜歡線性佈局,因爲它可以讓我在每個按鈕級別上都有力量。 取決於什麼適合這個傢伙...... :) –
但嵌套佈局是不利於表演。 –
以下爲3個按鈕的示例XML佈局正如你所說
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close"
android:layout_centerHorizontal="true"
android:focusable="false"
android:focusableInTouchMode="false"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:focusable="false"
android:focusableInTouchMode="false"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous"
android:focusable="false"
android:focusableInTouchMode="false"/>
</RelativeLayout>
你應該看一看不同的佈局類。我認爲一個gridview是你想包括。 https://developer.android.com/guide/topics/ui/declaring-layout.html&https://developer.android.com/guide/topics/ui/layout/gridview.html – Karl
或者一個GridLayout,因爲一些按鈕可能會更大。 –
使用網格佈局..它在你需要這種佈局的地方很好地工作 –