音乐播放器 ViewFlipper 滑动屏幕
16lz
2021-01-23
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;
}
<?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;
}
更多相关文章
- 使用千千静听或手动创建Android播放列表的方法
- Android 使用Vitamio打造自己的万能播放器(6)――在线播放(播放列表
- Android 使用Vitamio打造自己的万能播放器(3)――本地播放(主界面、
- Android里面编写退出主程序的提示代码
- Android 仿抖音视频播放列表和评论列表
- Android 安卓使用MediaPlayer播放列表视频
- 狂刷Android范例之5:ApiDemos主程序框架分析