我有一个XML布局,我试图将一系列按钮添加到(A-Z)。到目前为止,我已经能够这样做了 - 但是它们看起来像是集中在左侧。我希望他们能够均匀分布 - 我认为使用的东西如:
delegate
将它们均匀地分布在屏幕上 - 但是我留下了多个错误说明:
protocol UIFormViewDelegate:NSObjectProtocol, UIScrollViewDelegate{
}
class UIFormView: UIScrollView {
override var delegate:UIFormViewDelegate?
}
截图: http://i.stack.imgur.com/OVfAf.png
当前来源:
android:layout_marginLeft="fill_parent"
android:layout_marginRight="fill_parent"
答案 0 :(得分:0)
错误:不允许使用字符串类型(在'layout_marginLeft'中,值为'fill_parent')。声明您不应该为此属性提供字符串值。你必须在pixel / dp / dip
中给出整数值ie)layout_marginLeft =“10px”
答案 1 :(得分:0)
我看到你在LinearLayout中有按钮。在这种情况下,您可以在子项(Buttons)上使用android:layout_weight设置。诀窍是不要在LinearLayout上使用具有可变数量按钮的android:weightSum。 下面的示例将沿LinearLayout拉伸按钮。如果您希望按钮大小保持固定,则将每个Button包装在另一个LinearLayout中(它将保存layout_weight属性)。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text_1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text_2"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text_3"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="text_4"/>
</LinearLayout>
</RelativeLayout>