Как сохранить соотношение сторон в текстовом представлении с изображением в Android? - PullRequest
0 голосов
/ 09 ноября 2019

я пытаюсь поместить изображение в 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, но изображение не сохраняет соотношение сторон. Есть идеи?

...