【问题标题】:How to Construct this Layout in Android?如何在 Android 中构建此布局?
【发布时间】:2014-02-17 18:24:54
【问题描述】:

我将如何在 Android 中构建此布局?

我希望所有三个元素都是 FrameLayout,所以在运行时,我可以在代码中插入一个片段 我有圆角和虚线角的代码。我只是在将框架布局放置在彼此之上时遇到问题。或者这 3 个元素应该是相对布局??

【问题讨论】:

  • 我猜它们应该是相对布局。框架布局并不真正意味着对齐等。

标签: android android-layout android-fragments android-framelayout


【解决方案1】:

所有三个元素都应该是框架布局,但根元素应该是相对布局。另请注意,在相对布局中,元素被定位为从最低到最高的层。 (从上到下的xml文件)第一个元素 - 是最低的,其次是在第一个之上,等等。

你的布局应该是这样的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/container_square_with_rounded_corners"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>

    <FrameLayout
        android:id="@+id/container_circle"   
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"/>

    <FrameLayout
        android:id="@+id/container_square"   
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 2018-09-06
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    • 2014-09-13
    相关资源
    最近更新 更多