音乐播放器 ViewFlipper 滑动屏幕

本文详细介绍了Android应用中导航栏布局与视图切换的实现方式,包括使用ViewFlipper进行视图动画效果的设置及点击事件响应,通过代码示例展示了如何根据不同场景调整视图显示顺序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/img_single_bg"
android:id="@+id/RelativeLayout_catalog">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/img_playback_bg"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/btn_layout" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_buttom_bt_list"
android:background="#00000000"
android:text="主页"
android:id="@+id/zy"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_buttom_bt_lrc"
android:background="#00000000"
android:text="播放列表"
android:id="@+id/bflb"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_buttom_bt_menu"
android:background="#00000000"
android:text="歌词"
android:id="@+id/gc"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img_buttom_bt_play"
android:background="#00000000"
android:text="声音"
android:id="@+id/sy"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="莲莲动听"
android:textSize="16dip"
android:gravity="center"
android:id="@+id/info"
/>

</LinearLayout>
<ViewFlipper
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btn_layout"
android:layout_alignParentLeft="true"
android:layout_above="@id/seekBar1"
android:id="@+id/flipper"
/>
</RelativeLayout>
在anim内加载进入动作。
主程序调用
private ViewFlipper flipper;
public void onClick(View v) {
View view = flipper.getCurrentView();
Object a = view.getTag();
int b = Integer.valueOf(String.valueOf(a)).intValue();
switch (v.getId()) {
case R.id.zy:
if (b > 1) {

flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
for (int i = 0; i < b - 1; i++) {
flipper.showPrevious();
}
}
break;
case R.id.bflb:
if (b > 2) {
flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
for (int i = 0; i < b - 2; i++) {
flipper.showPrevious();
}
} else if (b < 2) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
flipper.showNext();
}
break;
case R.id.gc:
if (b > 3) {
flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
flipper.showPrevious();
} else if (b < 3) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
for (int i = 0; i < 3 - b; i++) {
flipper.showNext();
}
}
break;
case R.id.sy:
if (b < 4) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
for (int i = 0; i < 4 - b; i++) {
flipper.showNext();
}
}
break;

}

}

private void initiaView(){
zy = (ImageButton) findViewById(R.id.zy);
bflb = (ImageButton) findViewById(R.id.bflb);
gc = (ImageButton) findViewById(R.id.gc);
sy = (ImageButton) findViewById(R.id.sy);
zy.setOnClickListener(this);
bflb.setOnClickListener(this);
gc.setOnClickListener(this);
sy.setOnClickListener(this);
flipper = (ViewFlipper) findViewById(R.id.flipper);
View view1 = addTextByText("HelloAndroid1");
view1.setTag(1);
View view2 = setList();
view2.setTag(2);
View view3 = setSongWord();
view3.setTag(3);
View view4 = addTextByText("HelloAndroid4");
view4.setTag(4);
flipper.addView(view1);
flipper.addView(view2);
flipper.addView(view3);
flipper.addView(view4);
}
public View addTextByText(String text) {
TextView tv = new TextView(this);
tv.setText(text);
tv.setGravity(1);
return tv;
}
public View setList() {
ListView lv = new ListView(this);
lv.setDrawSelectorOnTop(false);
lv.setCacheColorHint(0);
ListViewAdapter adapter = new ListViewAdapter(this, mMusicList);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// currentListItme = position;
// playMusic();
if (playMusicService != null) {
playMusicService.playMusic(position);
}
}
});
return lv;
}
public View addImageById(int id){
ImageView iv = new ImageView(this);
iv.setImageResource(id);
return iv;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值