【问题标题】:Background image (for TextView) as big as the TextView content背景图像(用于 TextView)与 TextView 内容一样大
【发布时间】:2016-12-14 17:21:09
【问题描述】:

我将背景图片设置为TextView

<TextView
   ...
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   android:background="@drawable/fumetto"
   ...
/>

问题是现在TextView 的大小没有它的内容那么大,但它和背景图片一样大。

有没有办法让背景图片适应TextView的大小,而不是让TextView适应其背景图片的大小?

提前谢谢你。

【问题讨论】:

  • 这应该可以正常工作。请检查您的父布局或发布更多代码。

标签: android android-layout textview


【解决方案1】:

你应该使用9 Patch Drawable。 这是developer guide

【讨论】:

  • 感谢您的帮助。我制作了一个 9 补丁图像,但现在 android studio 告诉我存在“重复”资源错误,因为现在我有 fumetto.png 和 fumetto.9.png。如果删除了 fumetto.png(甚至在清理和重建项目之后),我会收到另一个错误。你知道如何在android studio上解决这个问题吗?
  • 删除可绘制对象后出现的错误是什么? @MDP
【解决方案2】:

使用可从资源中绘制的形状

 <TextView
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/button_border"
     android:text="adswss" />

按钮边框

`<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle" >
            <corners android:radius="15dp"></corners>
            <stroke android:width="2dp" android:color="@color/color_bg" />
        </shape>
    </item>
</selector>'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多