【问题标题】:Relative Layout containing FrameLayout and few other components包含 FrameLayout 和一些其他组件的相对布局
【发布时间】:2013-11-29 07:47:09
【问题描述】:

首先请原谅我对这个主题的命名很糟糕。

我有以下布局设置:

<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"
    tools:context=".PersonDetails" >
    <FrameLayout
        android:id="@+id/bannerLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageView
            android:id="@+id/coverImage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitStart"
            android:src="@drawable/default_cover">
        </ImageView>

        <ImageView
            android:id="@+id/thumbImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left|bottom"
            android:scaleType="fitStart"
            android:src="@drawable/fingerprint_ic" />
    </FrameLayout>
    <TextView
        android:id="@+id/textName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textColor="#55FF55"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

我想要实现的是有一个横幅(很像跨越屏幕顶部的 facebook 封面)。并在横幅的左角放一张缩略图。

横幅的高度应仅占屏幕高度的 1/4 左右。因为我需要其余的空间来放置其他组件。

在横幅的正下方,我想要一个 TextView(在左侧)和一个按钮在右侧。

到目前为止,我只能将缩略图放在横幅顶部,但我不知道如何将其放在左下角(我可以使用 marginTop 设置它,但我认为这不是正确的方法这样做)。

有谁知道如何做到这一点?谢谢。

编辑#1:

这是用户界面

【问题讨论】:

  • 提供一些ui图。

标签: android android-layout android-relativelayout android-framelayout


【解决方案1】:

根据你的描述,我认为你想做这样的事情:

我使用了带有 2 个布局的线性布局作为内容。使用 android:layout_weight 属性,我们可以让顶部布局占据 1/4 的空间,而底部布局则使用其余部分。

然后将图标定位在顶部布局中,我们使用 alignParentBottom 使其粘在底部。

<LinearLayout 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"
tools:context=".PersonDetails"
android:orientation="vertical">


<RelativeLayout
    android:id="@+id/bannerLayout"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <ImageView
        android:id="@+id/coverImage"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/default_cover"></ImageView>

    <ImageView
        android:id="@+id/thumbImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:scaleType="fitStart"
        android:src="@drawable/fingerprint_ic" />
</RelativeLayout>



<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="3"
    android:layout_margin="10dp">

    <TextView
        android:id="@+id/textName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="40dp"
        android:text="Large Text"
        android:textColor="#55FF55"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_alignParentEnd="true"/>

</RelativeLayout>

</LinearLayout>

【讨论】:

  • 是的,这正是我想要实现的。我想我可以为此使用 FrameLayout。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-18
  • 1970-01-01
相关资源
最近更新 更多