抱歉,我的布局效果不佳。我试图在一些文本字段旁边的另一个按钮旁边添加一个按钮。当我说按钮在第3列时,在预览中它会跳到右边的屏幕......我做错了什么?
{{1}}
答案 0 :(得分:0)
请检查以下答案,我已添加 LinearLayout 和 weightSum 以保持
它喜欢 EditText - >按钮 - >按钮强>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/mainGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5" >
<ListView
android:id="@+id/itemListView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:padding="5dp" />
<TextView
android:id="@+id/Instructions"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="0.7"
android:gravity="start|left"
android:padding="5dp"
android:singleLine="false"
android:text="Enter details of item to add to you timer list below. Enter the times in seconds. The finish by refers to if you need an item to finish before the end, again in seconds." />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.3"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<EditText
android:id="@+id/itemName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:hint="Item to add"
android:inputType="textPersonName" />
<EditText
android:id="@+id/itemTime"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:hint="Time in seconds"
android:inputType="time"
android:nextFocusDown="@+id/finishTime"
android:nextFocusForward="@+id/finishTime"
android:nextFocusRight="@+id/finishTime" />
<EditText
android:id="@+id/finishTime"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:hint="Seconds it needs to finish by"
android:inputType="time" />
</LinearLayout >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/addItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="16dp"
android:layout_weight="1"
android:gravity="center"
android:onClick="addItem"
android:padding="16dp"
android:text="Add" />
<Button
android:id="@+id/timerButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="16dp"
android:layout_weight="1"
android:gravity="center"
android:text="Start Timer" />
</LinearLayout >
</LinearLayout >
</LinearLayout >
</LinearLayout >