【问题标题】:Why wrap_content has no effect?为什么 wrap_content 没有效果?
【发布时间】:2016-10-11 21:16:07
【问题描述】:

wrap_content 设置在RecycleView 支架中:

<?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:background="@android:color/black">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView3"
        android:textColor="@android:color/white"
        android:textSize="17dp"
        android:background="@drawable/bubbleblue170x140_2" />

</RelativeLayout>

但是TextView 中的文本没有被包裹,气泡中有很多空白空间,TextView 内部。

如何强制在 iOS 版本中看到这样的内容:

在 Android 中使用9-patch 图像作为background

【问题讨论】:

  • 即兴发挥,您的 9-patch PNG 太高了。 9 补丁 PNG 扩展但不收缩。文本宽度设置为match_parent,所以我认为您关心的是wrap_content 高度上的额外垂直空白。
  • 在 TextView android:layout_width="wrap_content" 中使用 9-patch PNG
  • TextView 不能小于 9补丁。这是最小尺寸

标签: android android-layout android-recyclerview android-wrap-content


【解决方案1】:

你的文本视图的高度是换行,大尺寸是因为你的 9patch 图像(可能有一个大尺寸)

并且它的宽度是你在 xml 布局中想要的匹配父级。

只需改变你的 9 补丁的大小并让宽度也包含内容

【讨论】:

    【解决方案2】:

    调整 9patch 的大小。您还应该将RelativeLayout 的高度和宽度更改为wrap_content。或者,更好的是,您应该删除RelativeLayout(它似乎没用)。

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      • 2015-05-31
      • 2021-04-17
      • 2018-02-24
      • 2011-05-05
      • 2021-04-10
      • 1970-01-01
      相关资源
      最近更新 更多