Android4.0.4系统源码中,横竖屏采用不同的布局,为什么竖屏切换到横屏,有时不会显示歌词

zhongyuanceshi 2012-11-10 08:16:40
RT。横竖屏采用代码一样,只是布局文件不一样。竖屏播放音乐、显示歌词。此时竖屏切换到横屏,有时不会显示歌词,要再次重新播放歌曲才显示歌词。
请问:这是什么原因呢?
...全文
284 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhongyuanceshi 2012-11-13
  • 打赏
  • 举报
回复
我只是改了布局。歌词代码部分都没改。为什么原始的切换没问题,改布局后的就有问题?
zhongyuanceshi 2012-11-12
  • 打赏
  • 举报
回复
哪位有碰到过?提供分析方法
zhongyuanceshi 2012-11-12
  • 打赏
  • 举报
回复
切换时并没有重启activity,因为在androidmanifest.xml文件有配置翻转。并且下面函数 onConfigurationChanged在切换时调用了,并没有再次调用onCreate

    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);

        mAlbumArtWorker = new Worker("album art worker");
        mAlbumArtHandler = new AlbumArtHandler(mAlbumArtWorker.getLooper());

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // Get the current orientation
        mIsLandScape = (getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE);
        updateUI();
    }

    void updateUI() {
        setContentView(R.layout.audio_player_with_lrc);

        mLyricsFrame = (FrameLayout)findViewById(R.id.lyrics_frame); 
  
        mLrcMode = MusicUtils.getIntPref(this, "lyricMode",ScrollLrcView.LRC_MODE_SINGLE);
            mScrollLrcView = (ScrollLrcView) findViewById(R.id.lyrics_view);
            mScrollLrcView.setOnTouchListener(new OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
          ((ImageView) findViewById(R.id.lyrics_shift)).setOnClickListener (
                new View.OnClickListener () {
                    public void onClick(View v) {
                        if (mLrcMode == ScrollLrcView.LRC_MODE_MULTIPLE) {
                            mLrcMode = ScrollLrcView.LRC_MODE_SINGLE;
                        } else if (mLrcMode == ScrollLrcView.LRC_MODE_SINGLE) {
                            mLrcMode = ScrollLrcView.LRC_MODE_MULTIPLE;
                        }
                        MusicUtils.setIntPref(MediaPlaybackActivity.this, "lyricMode", mLrcMode);
        
                        updateLyricsFrame();
                        try {
                            if (!mScrollLrcView.reSetupLyrics(
                                    MediaPlaybackActivity.this, mLrcMode, (int)mService.position())) {
                                return;
                            }
                        } catch (RemoteException ex) {
                            throw new LrcScrollException();
                        }
        
                        mHandler.sendEmptyMessage(UPDATE_LRC);
                    }
                }
            );
        } 

    @Override
    public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);
        // When configuration change, get the current orientation
        mIsLandScape = (getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE);
        // when configuration changed ,set mIsShowAlbumArt = true to update album art
        mIsShowAlbumArt = true;
        updateUI();
        // When back to this activity, ask service for right position
        mPosOverride = -1;
        
            if (null != mScrollLrcView) {
                mScrollLrcView.resetHighlight();
            }
        // Refresh action bar menu item
        invalidateOptionsMenu();
    }
如果在onConfigurationChanged中不调用 updateUI,怎切换时歌词显示正常,但横屏时用的还是竖屏布局。布局不对。原始的布局歌词显示是在最下面,而修改后的竖屏布局如下:

<FrameLayout
	            android:id="@+id/lyrics_frame"
	            android:layout_weight="1"
	            android:layout_below="@+id/linear1"
	            android:layout_width="match_parent"
	            android:layout_height="wrap_content"
	            android:layout_gravity="center_vertical">

	            <LinearLayout
	                android:id="@+id/lyrics_layout"
	                android:layout_width="match_parent"
	                android:layout_height="wrap_content"
	                android:layout_gravity="center_vertical"
	                android:orientation="vertical">

	                <com.android.music.ScrollLrcView
	                    android:id="@+id/lyrics_view"
	                    android:layout_width="match_parent"
	                    android:layout_height="0dip"
	                    android:layout_weight="1"
	                    android:fadingEdge="vertical"
	                    android:scrollbars="none" />

	            </LinearLayout>

	            <ImageView
	                android:id="@+id/lyrics_shift"
	                android:layout_width="0dip"
	                android:layout_height="45dip"
	                android:layout_gravity="center_horizontal"
	                android:layout_alignParentTop="true"
	                android:gravity="top"
	                android:focusable="false">
	            </ImageView>

	            <View
	                android:layout_width="0dip"
	                android:layout_height="1px"
	                android:background="#ffffffff">
	            </View>

	        </FrameLayout>
		</RelativeLayout>
	</RelativeLayout>
louyong0571 2012-11-12
  • 打赏
  • 举报
回复
没代码,不好判断了。
zy1235678 2012-11-12
  • 打赏
  • 举报
回复
应该是切换时又重启了前面的Activity导致的吧,在生命周期的某个方法中再显示一次
zhongyuanceshi 2012-11-12
  • 打赏
  • 举报
回复
咋没人呢?会不会是控件的问题,歌词显示用了一个ScrollView
zhongyuanceshi 2012-11-11
  • 打赏
  • 举报
回复
咋没人呢?没有其他分析的方法?

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧