zoukankan      html  css  js  c++  java
  • Android TextView(同时显示图片+文字)

    见上图:需要图片和文字 在一起

    之前的做法是用两个控件组成

    <LinearLayout>
        <ImageView />
        <TextView />
    </LinearLayout>

    今天读人家的源码,发现原来一个TextView就可以实现:

            <TextView
                android:id="@+id/btn_middle"
                style="@style/style_topbar_textview_shadow"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:drawableLeft="@drawable/actionbar_icon"
                android:drawablePadding="4.0dip"
                android:ellipsize="end"
                android:gravity="center_vertical"
                android:singleLine="true"
                android:text="@string/app_name"
                android:textColor="#ffffffff"
                android:textSize="@dimen/size_big"
                android:visibility="visible" />

    加粗的代码,就是其中的关键:

    android:drawableLeft="@drawable/actionbar_icon" --> 这张图片位于文字的左边;这里当然可以让其位于文字的右边;右边和左边可以同时设置
    android:drawablePadding="4.0dip" --> 图片与文字之间的距离
  • 相关阅读:
    ABP 往前端返回详细的错误信息
    ABP 报错1
    three.js 测试1
    three.js 添加 图形控制界面 gui
    three.js 设置透明度
    three.js 基础使用1
    three.js 添加环境光
    three.js 添加三维坐标系
    P2690 接苹果
    [USACO08FEB]修路Making the Grade
  • 原文地址:https://www.cnblogs.com/zhou-guobao/p/4651192.html
Copyright © 2011-2022 走看看