【发布时间】:2016-05-20 19:42:01
【问题描述】:
我在RelativeLayout 中有两个LinearLayout。我只想在一个 LinearLayout 内执行此 LinearLayout,以便我的子控件将显示在 1 LinearLayout 内。这样我就可以将这个 LinearLayout 分组并显示
使用不同的背景颜色android:background="@drawable/my_custom_background,以便所有子控件都耦合到其中。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#0B95BA"
android:minWidth="25px"
android:minHeight="25px">
<LinearLayout
android:id="@+id/linearLayoutCont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp">
<TextView
android:id="@+id/txtViewCont"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Contact Billing"
android:gravity="center"
android:textSize="25sp"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutContBillingCall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/linearLayoutCont"
android:layout_marginTop="5dp">
<Button
android:text="Call"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_gravity="right"
android:background="@drawable/ButtonStyle"
android:id="@+id/btnContCall"
android:drawableLeft="@drawable/PhoneCall" />
<Button
android:text="Email"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#FFFFFF"
android:layout_gravity="right"
android:background="@drawable/ButtonStyle"
android:id="@+id/btnEmail"
android:drawableLeft="@drawable/Email" />
</LinearLayout>
</RelativeLayout>
和 o/p 应该在图片上方,例如 Contact 在中心,两个按钮(Call 和 Email)在联系人同一个角落下方。还有一件事我想问我如何在这两个按钮之间创建一个空间。
【问题讨论】:
-
您正在尝试将 2 个具有不同方向的 LinearLayouts 组合在一起 - 无法将它们组合成一个。只需使用 RelativeLayout 来定位控件,而无需任何 LinearLayouts。
-
@adelphus 我试过了,但没有显示子控件。
-
@adelphus 我试过 android:id="@+id/linearLayoutCont" 它在一行中显示我的子控件 Contact 、 Call 、 Email ,即单行我希望它在上面的 COntact 和 Call and下面的电子邮件按钮。
-
这就是为什么你使用 layout_below、layout_toLeftOf 和其他类似的属性来定位 RelativeLayouts 中的元素。我认为您需要阅读有关如何使用 RelativeLayout 的文档。
-
您可以使用线性布局而不是相对布局,然后在其中嵌套具有所需方向、宽度和高度的其他线性布局。
标签: android android-layout xamarin xamarin.android