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,但是图像不保持宽高比。有什么想法吗?