【问题标题】:How to get Edittext(Multiline) leftdrawable on top position如何在顶部位置获得 Edittext(Multiline) leftdrawable
【发布时间】:2015-11-20 12:23:20
【问题描述】:

我正在使用 EdittexttextMultiLine 属性。我使用android:gravity="top" 在顶部位置获得了edittext 文本。但我无法获得android:drawableLeft="@drawable/ic_message" 的最高位置。

我希望android:drawableLeft="@drawable/ic_message" 在顶部位置(消息文本的左侧)

编辑

我的Edittext xml 如下:

<EditText
    android:id="@+id/edtContactMessage"
    style="@style/styleRoundedEdittext"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/tendp"
    android:drawableLeft="@drawable/ic_message"
    android:gravity="top"
    android:hint="@string/strMessage"
    android:imeOptions="actionDone"
    android:inputType="textMultiLine"
    android:lines="5"
    android:maxLength="500"
    android:minHeight="120dp"
    android:scrollbars="vertical"
    android:singleLine="false" />

【问题讨论】:

  • 您可以为此使用相对或框架布局。
  • 给我看你的EditText,我会试着把它转换成你想要的

标签: android android-edittext android-drawable


【解决方案1】:

不可能像这样在顶部位置的 EditText 上设置左侧可绘制对象,您需要将 EditText 包装在父布局中,在那里您可以放置​​一个在此位置绘制图标的 ImageView。

这是一个例子:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@android:drawable/edit_text"
android:orientation="horizontal">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:src="@android:drawable/ic_menu_send"
    android:scaleType="fitStart"
    android:contentDescription="message icon"
    />

<EditText
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:background="@null"
    android:padding="4dp"
    android:text="Message"
    android:inputType="textMultiLine"
    android:gravity="top"
    android:layout_weight="1" />

</LinearLayout>

【讨论】:

  • 感谢您的回答! :)
【解决方案2】:

你可以这样做:

 <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        **<!-- Edit text with drawable at top left -->**
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@drawable/image">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/edit"
                android:hint="Enter text"
                android:maxLines="10"
                android:inputType="textMultiLine" />
        </FrameLayout>
 </RelativeLayout>

希望对你有帮助。

【讨论】:

    【解决方案3】:

    根据 TouchBoarder 的回答,我在顶部位置得到了 Edittext(Multiline) leftdrawable :)

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@drawable/rounded_edittext"
        android:orientation="horizontal">
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="message icon"
            android:paddingBottom="@dimen/tendp"
            android:paddingLeft="@dimen/tendp"
            android:paddingTop="@dimen/tendp"
            android:scaleType="fitStart"
    
            android:src="@drawable/ic_message" />
    
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@null"
            android:gravity="top"
            android:inputType="textMultiLine"
            android:padding="4dp"
            android:text="Message" />
    
    
    </LinearLayout>
    

    输出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-17
      • 2019-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多