Вот XML-макет.Почему ImageView setImageResource() устанавливает размер изображения в match_parent?
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:text="@string/title"
android:textSize="@dimen/title_textSize"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/main_text_color"/>
<ImageView
android:id="@+id/play_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true"
android:onClick="clickPlay"
android:src="@drawable/pause"
/>
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp"
android:background="@null"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="10dp"
android:paddingTop="12dp"
android:progressDrawable="@drawable/seek_progress"
android:thumb="@drawable/seek_thumb"/>
<ImageView
android:id="@+id/restart_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/play_img"
android:layout_centerHorizontal="true"
android:onClick="clickRestart"
android:src="@drawable/restart"
android:visibility="invisible"
/>
Вот метод ClickPlay()
public void clickPlay(View v) {
if (playerCurrent != null && playerCurrent.isPlaying()) {
playerCurrent.pause();
playerBackground.pause();
imgPlayPause.setImageResource(R.drawable.play);
mVolumeSeekBar.setVisibility(View.INVISIBLE);
imgRestart.setVisibility(View.VISIBLE);
mIsPlaying = false;
} else {
playerCurrent.start();
playerBackground.start();
imgPlayPause.setImageResource(R.drawable.pause);
mVolumeSeekBar.setVisibility(View.VISIBLE);
imgRestart.setVisibility(View.INVISIBLE);
mIsPlaying = true;
}
}
Однако, когда я изменить изображение с паузы играть, играть изображение получить размер match_parent
, но когда Я снова нажимаю и изображение меняет изображение Пауза, оно получает нормальный размер wrap_content
.
Изображения как для воспроизведения, так и для паузы идентичны!
Вот образ того, как она выглядит до и после (из них окрашены, так что вы лучше смотреть размер)
Попробуйте использовать один и тот же чертеж в обоих случаях, чтобы исключить проблемы с ресурсами. –
Вы играете и приостанавливаете изображения одинакового размера в пикселях? – Lamorak
@ Lamorak Да, идентичные – sandalone