【问题标题】:This Tag And Its Children Can Be Replaced by One <TextView/> And a Compound Drawable这个标签和它的孩子可以被一个 <TextView/> 和一个复合 Drawable 替换
【发布时间】:2013-01-20 04:31:29
【问题描述】:

我查看了类似的问题并使用了它的答案,但是如果我将它们组合成 1 TextView 并放入 android:drawableTop= 它会显得非常奇怪,因为我现在拥有它只是将图像堆叠在文本之上这就是我想要的。

原创

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Navigation" >

    <ImageView
        android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:contentDescription="@string/logo_name"
        android:src="@drawable/generic_logo" />

    <TextView
        android:id="@+id/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/about"
        android:textSize="55sp"
        android:onClick="onClick"
        android:clickable="true" />

</LinearLayout>

复合

    <TextView
        android:id="@+id/about"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/about"
        android:textSize="55sp"
        android:onClick="onClick"
        android:clickable="true"
        android:drawableTop="@drawable/generic_logo" />

</LinearLayout>

Compound 将图像拉伸超出了我模拟的 android 的参数。如何解决此问题并消除警告?

【问题讨论】:

    标签: android xml eclipse android-emulator


    【解决方案1】:

    所以就测量和布局而言,这两者实际上是在做完全不同的事情。首先是计算图片需要多少空间,将其放在那里,计算文本需要多少空间,然后将其放置在图像下方。

    第二个是确定文本需要多少空间。然后在背景的顶部绘制图像,将其缩放以适应文本使用的整个空间。然后它在上面绘制文本。

    如果您不想拉伸图像,请使用第一个版本。第二个版本是错误的。复合可绘制对象用于诸如 9 个补丁之类的东西,其中单个背景图像被分成几部分。

    如果这些都不是你真正想要的,请解释那是什么,我们会看看我们是否能弄清楚如何做到这一点。

    【讨论】:

    • 那么如果第一个版本没有错,为什么它会向我抛出这个警告?
    • 因为一些效率工具认为你可以很聪明。这并不意味着该工具是正确的。您的原始答案是完全合法的 xml,并且更易于理解和维护。这是正确的答案。
    • 那么,当我打算使用第一个答案时,如何在eclipse中抑制警告?我的意思是,我知道这是正确的,但这个警告真的让我很烦。
    • 我通过切换到图形布局删除了警告,并在那里抑制了警告。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2011-12-08
    • 2016-10-13
    • 2014-12-04
    相关资源
    最近更新 更多