【问题标题】:How to set ImageView in edittext [duplicate]如何在edittext中设置ImageView [重复]
【发布时间】:2018-09-04 09:25:03
【问题描述】:

我正在使用带有 drawableLeft 属性的 EditText 并在左侧设置 ImageView 以显示移动图标。我的问题是如何将 Imageview 放入 EditText?

请帮帮我。

其实我也想要这样。

我尝试过使用水平的线性布局。下面是xml代码。

<LinearLayout
       android:weightSum="2"
       android:layout_below="@id/welcome"
       android:orientation="horizontal"
       android:layout_width="match_parent"
       android:layout_height="wrap_content">

        <de.hdodenhof.circleimageview.CircleImageView
            android:layout_weight="1"
            android:layout_gravity="center"
            android:id="@+id/image_mobile"
            android:layout_width="@dimen/_50sdp"
            android:layout_height="@dimen/_50sdp"
            android:src="@mipmap/ic_launcher" />


        <EditText
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_30sdp"
            android:layout_toRightOf="@+id/image_mobile"
            android:hint="Mobile number"
            android:inputType="text" />

   </LinearLayout>

但我无法调整图像视图和编辑文本。

【问题讨论】:

  • 如果你只是想用它显示任何图像,你可以使用left_drawable和edittext
  • 获得所需外观的简单方法是为您的线性布局设置一个可绘制对象,它会给出您想要的印象。

标签: android xml imageview


【解决方案1】:

你应该使用android:drawableStart

要绘制到文本开头的drawable。

演示

<EditText
     ......
     android:drawableStart="@drawable/your_icon"
     android:drawablePadding="5dp"
    />

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-03
相关资源
最近更新 更多