gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 22:58:55 26 4
gpt4 key购买 nike

我正在尝试将 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com