这是XML布局。
然而,当我将图像从暂停更改为播放时,播放图像的大小变为
播放和暂停图像完全相同!
以下是更改前后的图像(已进行颜色处理以更好地查看大小):
<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
大小。播放和暂停图像完全相同!
以下是更改前后的图像(已进行颜色处理以更好地查看大小):