【问题标题】:This tag and its children can be replaced by one and a compound drawable这个标签和它的孩子可以被一个和一个复合drawable替换
【发布时间】:2013-04-10 14:46:22
【问题描述】:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:orientation="horizontal"

 >

<ImageView

    android:id="@+id/file_icon"
    style="@style/fileChooserIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/desc" />

<TextView
    android:id="@+id/file_name"
    style="@style/fileChooserName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     />

错误:This tag and its children can be replaced by one &lt;TextView/&gt; and a compound drawable

我是 android 新手,不完全理解错误是什么。某些解决方案很难使它复合但没有得到它。

【问题讨论】:

标签: android xml eclipse


【解决方案1】:

使用TextView的setCompoundDrawable*()方法,或者使用android:drawableLeft,将TextView和ImageView合并为一个。

例子:

你去

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:layout_marginTop="10dp"  
android:padding="5dp" >

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="My Compound Button" />

<ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/my_drawable" />
</LinearLayout>

<TextView  
    android:layout_marginTop="10dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:text="My Compound Button" 
    android:drawableRight="@drawable/my_drawable"
    android:padding="5dp" />

【讨论】:

  • 一个疑问:我应该更改整个代码还是只更改 textview 和 imageview?
  • 您可以替换整个 LinearLayout 元素。
  • @Kirarahul 您可以使用 setCompoundDrawablesWithIntrinsicBounds() - developer.android.com/reference/android/widget/…, int, int, int) 以编程方式设置它
  • 这里如何设置图片大小
  • 复合drawable后如何改变图像大小和色调?
猜你喜欢
  • 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
相关资源
最近更新 更多