歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發:如何在EditText中設置固定圖片

Android開發:如何在EditText中設置固定圖片

日期:2017/3/1 11:15:00   编辑:Linux編程

如下圖,在EditText中顯示圖片

其原理就是在相對布局(RelativeLayout)的基礎上用ImageView實現

代碼如下:

  1. <RelativeLayout>
  2. <EditText Android:id="@+id/edt_operator_name" style="@style/syncEditText"
  3. android:hint="@string/hint_operator_name" />
  4. <ImageView android:id="@+id/syncOperatorImg" style="@style/syncImageView"
  5. android:layout_alignLeft="@+id/edt_operator_name"
  6. android:layout_alignTop="@+id/edt_operator_name"
  7. android:layout_alignBottom="@+id/edt_operator_name" android:src="@drawable/sync_operator" />
  8. </RelativeLayout>
這裡只是局部代碼,其他一些自定義的樣式或者引用沒有寫出來,知道關鍵的地方就行了,上面代碼中最關鍵的是:
  1. android:layout_alignLeft="@+id/edt_operator_name"
  2. android:layout_alignTop="@+id/edt_operator_name"
  3. android:layout_alignBottom="@+id/edt_operator_name" android:src="@drawable/sync_operator"
這幾句的意思就是讓讓syncOperatorImag的左部,上部和上部與edt_operator_name對齊。

注意:一定是在RelativeLayout的基礎上,否則不行。

Copyright © Linux教程網 All Rights Reserved