【发布时间】:2015-07-02 03:42:47
【问题描述】:
我是安卓新手。我还尝试了 fill_parent,match_parent 而不是 wrap_content。我想要在一行中有两个带有背景图像的按钮。我尝试使用 weightSum="2" 并且每个按钮都有 layout_weigh="1"。但它不起作用。请有人建议我哪里出错了。我的 XML 文件在下面
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="2">
<Button
android:id="@+id/button5"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="@drawable/theatre"
android:gravity="bottom|center_horizontal"
android:paddingBottom="18dp"
android:text="THEATRE"
android:textColor="@color/green" />
<Button
android:id="@+id/butt3"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="@drawable/hospital_icon"
android:gravity="bottom|center_horizontal"
android:paddingBottom="18dp"
android:text="HOSPITAL"
android:textColor="@color/green" />
<Button
android:id="@+id/button1"
android:layout_weight="1"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:background="@drawable/pubs"
android:gravity="bottom|center_horizontal"
android:paddingBottom="18dp"
android:text="PUBS"
android:textColor="@color/green" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
style="?android:attr/borderlessButtonStyle"
android:layout_gravity="left|top"
android:layout_marginTop="4dp"
android:layout_row="1"
android:background="@drawable/hotel"
android:gravity="bottom|center_horizontal"
android:paddingBottom="18dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:text="HOTELS"
android:textColor="@color/green" />
<Button
android:id="@+id/button6"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:background="@drawable/mall"
android:gravity="bottom|center_horizontal"
android:paddingBottom="18dp"
android:text="MALLS"
android:textColor="@color/green" />
<Button
android:id="@+id/button4"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:background="@drawable/monum"
android:gravity="bottom|center_horizontal"
android:paddingBottom="18dp"
android:text="MONUMENTS"
android:textColor="@color/green" />
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:text="EXPENSE CALCULATOR"
android:textColor="@color/green" />
</LinearLayout>
【问题讨论】:
-
orientation = "horizontal" 见这里stackoverflow.com/questions/6116910/…
-
嗨 Nimit 我认为您必须在 LinearLayout 中要求相同大小的按钮,对吗?
-
在 xml 中将方向从垂直更改为水平。
标签: android