【问题标题】:Stop views overlapping when device is horizontal : Android当设备水平时停止视图重叠:Android
【发布时间】:2013-09-05 16:53:55
【问题描述】:

我有以下 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:padding="2.0dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">

<TextView
        android:textSize="14.0sp"
        android:textStyle="bold"
        android:textColor="#ff449def"
        android:layout_gravity="top|left|center"
        android:id="@id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
<TextView
        android:layout_gravity="left"
        android:id="@id/eventvenue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name" />
<TextView
        android:layout_gravity="bottom|left|center"
        android:id="@id/datetime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/eventvenue" />
<TextView
    android:layout_gravity="left"
    android:id="@+id/datetime2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/datetime" />
<ImageView
        android:layout_gravity="right"
        android:id="@id/customlistrowlogo"
        android:padding="5.0dip"
        android:layout_width="80.0dip"
        android:layout_height="80.0dip"
        android:scaleType="fitXY"
        android:cropToPadding="true"
        android:layout_alignTop="@id/name"
        android:layout_alignBottom="@id/datetime2"
        android:layout_alignParentRight="true"
        android:contentDescription="logo" />

</RelativeLayout>

当应用程序处于垂直模式时,如果其中一个文本视图中的文本太长,则它将换行到下一行并且不会覆盖图像。

但是,当我处于水平模式时,文本不会换行到下一行,而是被图像覆盖。

垂直 ::

----------------------------
|                    image |
|text text text tex  image |
|t wraps around tex  image |
|                          |
|                          |
|                          |
|                          |
|                          |
|                          |
|                          |
|                          |
|                          |
|                          |
|                          |
---------------------------- 

水平::

---------------------------------------------------------------
|                                                              |
|     text                                           image     |
|     text text text text text text text text text teimage     |
|                                                              |
|                                                              |
|                                                              |
|                                                              |
|                                                              |
|                                                              |
|                                                              |
|                                                              |
---------------------------------------------------------------

与在垂直模式下文本下降到下一行的垂直模式不同,文本隐藏在图片后面并且不会转到下一行

【问题讨论】:

  • 您的示例 xml 并没有真正显示任何内容,因为您的所有控件都有 wrap_content 这导致几乎不可见。请查看您的示例代码。
  • @rekire 你是什么意思?不关注
  • 我无法理解您的问题,因为您所有控件的宽度都为零。
  • @rekire 见上图

标签: android xml textview android-imageview android-relativelayout


【解决方案1】:

您可以在 layout-land 文件夹中为横向模式创建一个单独的 XML 文件。每当您的配置更改时,android 都会尝试重新绘制布局。最好有一个横向视图的布局。

【讨论】:

  • 我不同意你的看法,一般来说,我总是尽量避免轮换重启,这带来的麻烦多于帮助。恕我直言,在极少数情况下,soecal 布局是有意义的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-14
  • 2017-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多