如何在Android中使用图像在textview中保持长宽比?

im试图将图像放入textView中。我在活动的onCreate中有此内容

TextView imagenText = findViewById(R.id.imagenText);
        Bitmap imagen = getIntent().getParcelableExtra("imagen");
        imagenText.setBackground(new BitmapDrawable(getResources(),imagen));

并在xml中:

<android.support.constraint.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"
   tools:context=".ProductDetailactivity">

   <TableLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       tools:layout_editor_absoluteX="132dp"
       tools:layout_editor_absoluteY="110dp"
       android:layout_marginTop="16dp"
       android:layout_marginLeft="16dp"
       android:layout_marginRight="16dp">
   ...
   <TableRow
           android:layout_width="match_parent"
           android:layout_height="match_parent" >

           <TextView
               android:id="@+id/imagenLabel"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginTop="30dp"
               android:ems="10"
               android:importantForAutofill="no"
               android:text="@string/imagen"
               android:textStyle="bold" />
       </TableRow>

       <TableRow
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:gravity="center_horizontal" >

           <TextView
               android:id="@+id/imagenText"
               android:layout_width="wrap_content"
               android:layout_marginTop="10dp"
               android:layout_height="150dp" />
       </TableRow>
   ...

我需要图像的高度为150dp,但是图像不保持宽高比。有什么想法吗?

a840866712 回答:如何在Android中使用图像在textview中保持长宽比?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3134397.html

大家都在问