我有一个带有drawabletop图像的TextView,但是图像很大,我需要调整它的大小:
<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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/football_pitch">
<TextView
android:id="@+id/playerNameTop"
android:layout_width="350dp"
android:layout_height="358dp"
android:layout_marginStart="16dp"
android:drawableTop="@drawable/ic_football_top"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</RelativeLayout>
我尝试通过设计 View 调整它的大小,但当我缩小尺寸时它只会裁剪图像。 如何在不裁剪图像的情况下调整图像本身的大小?
我想如果我把图像变小,我就必须增加文本大小,我可以做得很好。 所以现在我需要缩小图像,但由于某种原因它也切断了图像的一侧:
[这张图片显示我通过设计 View 调整了它的大小。正如您所看到的,它已将底部裁剪掉,因此您看不到文本 1
最佳答案
我总是避免使用drawableTop
和其他类似的。以更可定制的方式进行:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_drawable"/>
<TextView
android:id="@+id/playerNameTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"/>
</LinearLayout>
关于java - 调整固定到 TextView 的可绘制顶部图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51286927/