【发布时间】:2015-03-19 17:28:04
【问题描述】:
这是 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。
播放和暂停图像是相同的!
这是它之前和之后的样子(为它们着色,以便您更好地查看尺寸)
【问题讨论】:
-
尝试在两种情况下使用相同的drawable来排除drawable资源的问题。
-
您是否播放和暂停相同大小的可绘制对象(以像素为单位)?
-
@Lamorak 是的,完全相同
-
它们在同一个文件夹中吗?这很奇怪..
-
@Lamorak 当然,两者都在 /drawable-large 中(7in 平板电脑资源)。是的,确实很奇怪。在我开始在平板电脑上进行测试之前,我实际上并没有在移动设备上注意到这一点。
标签: android android-layout android-imageview