android - 如何将 1600px x 1600px 图像适合 EditText 作为 android :background

标签 android xml android-studio

我正在尝试将 1600 像素 x 1600 像素的图像放入 EditText。 我尝试了 android:padding 的多种组合,但似乎都不起作用

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background=""
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.116" />

    <EditText
        android:id="@+id/imageView"
        android:layout_width="296dp"
        android:layout_height="80dp"
        app:srcCompat="@drawable/ButtonLogin"
        tools:layout_editor_absoluteX="57dp"
        tools:layout_editor_absoluteY="229dp" />


</androidx.constraintlayout.widget.ConstraintLayout>

This is what i get when i put the Image as an android:background

Issue

这是我的目标:

My Goal

有什么方法可以在这个特定的 XML 中,或者我是否必须更改图像的分辨率

最佳答案

注意: 为实现您的目标,您应该使用 EditText 而不是 ImageView。 (您必须在 .xml 中添加 EditText)

这是实现目标的方法

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="26dp"
        android:background="#3F4650"
        android:drawableLeft="@drawable/ic_person"
        android:hint="Username"
        android:textSize="28dp"
        android:textColorHint="#636A72"
        />

</RelativeLayout>

在 app > res > drawable > ic_person.xml 中为 EditText 中的人物图像创建 xml 文件或者您也可以使用不同的图像,只需更改 android:drawableLeft="@drawable/your_other_image"

<vector 
    android:height="72dp" 
    android:tint="#CED0CF"
    android:viewportHeight="24.0" 
    android:viewportWidth="24.0"
    android:width="72dp" 
    xmlns:android="http://schemas.android.com/apk/res/android">
        <path 
            android:fillColor="#FF000000" 
            android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

[ OUTPUT ]

关于android - 如何将 1600px x 1600px 图像适合 EditText 作为 android :background,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57133753/

相关文章:

c# - Dataset.WriteXml() 命名空间和前缀

android - 反混淆不适用于 android studio 3.0

android - 在 Android 中显示大图像

android - 如何在 Ubuntu 中安装 Android Studio?

android - 通过 onClickListener 按自定义适配器中的位置获取数据

java - 我可以将 LatLng 对象用作 double 对象吗?

android - 在android应用程序中使用BroadCastReceiver获取经纬度?

java - 现有 Realm 文件中字段 'String' 的无效类型 'id'

javascript - 如何使用 jquery 和 ajax 读取、解析和显示 xml

XML 站点地图呈现为纯文本