【问题标题】:RelativeLayout wrap_content width, circular dependencyRelativeLayout wrap_content 宽度,循环依赖
【发布时间】:2019-04-24 03:27:55
【问题描述】:

想要为新的 Android 版 Google Maps v2 API 设计一个自定义标记气球。我已经覆盖了 getInfoContents 但我现在的布局采用了 ym 自定义设计的整个屏幕宽度。我希望它以最大宽度环绕文本。

在线阅读后发现我的问题,可能是我在RelativeLayout中有循环依赖,这是不允许的。但是,我将如何将文本字段“位置”移动到布局的右侧,与标题一致但在右侧?

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

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        android:paddingBottom="2sp"
        android:paddingLeft="5sp"
        android:paddingTop="1sp"
        android:textColor="@color/list_item_title_color"
        android:textSize="15sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"sa
        android:layout_below="@id/title"
        android:ellipsize="end"
        android:maxLines="3"
        android:paddingBottom="3sp"
        android:paddingLeft="5sp"
        android:paddingRight="5sp"
        android:textColor="@color/list_item_text_color"
        android:textSize="13sp" />

    <TextView
        android:id="@+id/place"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:gravity="right"
        android:paddingRight="5sp"
        android:paddingTop="1sp"
        android:textColor="@color/list_item_date_color"
        android:textSize="13sp" />

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/icons"
        android:layout_width="fill_parent"
        android:layout_height="32dp"
        android:layout_below="@id/place"
        android:gravity="right"
        android:orientation="vertical"
        android:paddingBottom="2sp"
        android:paddingLeft="5sp"
        android:paddingRight="5sp" >
    </LinearLayout>

</RelativeLayout>

【问题讨论】:

  • 循环依赖在哪里?
  • 如果我理解正确,它在'android:layout_alignParentRight="true"'中。
  • 不,这不应该导致循环依赖,它不受上面任何其他东西的限制。有关更多信息,请参见此处:stackoverflow.com/questions/10916892/…

标签: android width android-relativelayout


【解决方案1】:

你不能添加:

android:layout_toRightOf="@id/title"

到你的地方 textview?

编辑:

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

<RelativeLayout
android:id="@+id/leftLayout"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:maxLines="1"
    android:paddingBottom="2sp"
    android:paddingLeft="5sp"
    android:paddingTop="1sp"
    android:textColor="@color/list_item_title_color"
    android:textSize="15sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"sa
    android:layout_below="@id/title"
    android:ellipsize="end"
    android:maxLines="3"
    android:paddingBottom="3sp"
    android:paddingLeft="5sp"
    android:paddingRight="5sp"
    android:textColor="@color/list_item_text_color"
    android:textSize="13sp" />

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/icons"
    android:layout_width="fill_parent"
    android:layout_height="32dp"
    android:layout_below="@id/place"
    android:gravity="right"
    android:orientation="vertical"
    android:paddingBottom="2sp"
    android:paddingLeft="5sp"
    android:paddingRight="5sp" >
</LinearLayout>

</RelativeLayout>

    <TextView
        android:id="@+id/place"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/leftLayout"
        android:gravity="right"
        android:paddingRight="5sp"
        android:paddingTop="1sp"
        android:textColor="@color/list_item_date_color"
        android:textSize="13sp" />
</RelativeLayout>

在这里,试试这个,但它没有经过测试。

【讨论】:

  • 感谢您的回答,但这只是将其放在标题的右侧,但我希望它一直位于右侧。 '|..................| |职称地点| |文字图标|
  • 然后你可以用另一个RelativeLayout包裹你的整个RelativeLayout,然后把你的textview放在这个外部布局中。然后设置为RightOf="@id/leftLayout"(leftLayout 是你现有RelativeLayout 的id)。
  • 我正在尝试不同的设置,但“地点”和“标题”相互重叠。他们都还在左边。
  • 我更新了我的答案,也许这对你有用。
  • 那更近了,但我仍然不知道如何让它看起来正确/有效。这就是我希望它没有重叠和过大的窗口的方式。这是我在问题中发布的代码。 i559.photobucket.com/albums/ss36/TutenStain/…
【解决方案2】:

除非我误解,否则您应该可以将“标题、地点和文本”包含在 linearlayout

<LinearLayout
android:id="@+id/textLL
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
//textViews
</LinearLayout>

现在使用

android:layout_toRightOf="@+id/textLL"

在您的“图标”布局中。或者这不是你想要的?

【讨论】:

  • 差不多,但我想要这样。感谢您的回复。 i559.photobucket.com/albums/ss36/TutenStain/…
  • 如果“地方”紧挨着“标题”,则将这两个放在LinearLayoutorientation='horizontal' 中,然后“文本”在LinearLayout 下方对齐
猜你喜欢
  • 2015-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-23
  • 1970-01-01
  • 2020-03-04
  • 2017-08-07
  • 1970-01-01
相关资源
最近更新 更多