首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >android布局:此标签及其子标签可以替换为一个<TextView/>和一个复合可绘制

android布局:此标签及其子标签可以替换为一个<TextView/>和一个复合可绘制
EN

Stack Overflow用户
提问于 2010-07-10 00:03:36
回答 11查看 48.9K关注 0票数 122

当我在一个特定的XML文件上运行layout时,我得到这样的结果:

代码语言:javascript
复制
 This tag and its children can be replaced by one <TextView/> 
and a compound drawable

应该对以下xml代码进行哪些更改:

代码语言:javascript
复制
<LinearLayout android:id="@+id/name_layout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:background="@drawable/grouplist_single_left_grey_area" >
                <ImageView android:id="@+id/photo_image"
                    android:layout_width="@dimen/thumbnail_width"
                    android:layout_height="@dimen/thumbnail_height"
                    android:paddingBottom="5dip"
                    android:paddingTop="5dip"
                    android:paddingRight="5dip"
                    android:paddingLeft="5dip"
                    android:layout_marginRight="5dip"
                    android:clickable="true"
                    android:focusable="true"
                    android:scaleType="fitCenter"
                    android:src="@*android:drawable/nopicture_thumbnail"
                    android:background="@drawable/photo_highlight" />
                <TextView android:id="@+id/name"
                    android:paddingLeft="5dip"
                    android:layout_weight="1"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>

这是它在屏幕上的样子:

相机图标是默认图标。点击该按钮,用户可以选择另一张图片。

EN

回答 11

Stack Overflow用户

回答已采纳

发布于 2012-01-14 06:43:36

为了扩展Romain Guy的答案,这里有一个例子。

之前:

代码语言:javascript
复制
<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>

之后:

代码语言:javascript
复制
<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" />
票数 163
EN

Stack Overflow用户

发布于 2010-07-10 00:06:12

使用TextView的setCompoundDrawable*()方法或使用android:drawableLeftTextViewImageView合并为一个。

票数 104
EN

Stack Overflow用户

发布于 2012-08-08 09:41:43

我想我也会尝试一些额外的双关语:您可以使用android:drawablePadding在图像和文本之间添加填充。https://stackoverflow.com/a/6671544/1224741

票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3214424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档