我正在使用umano SlidingUpPanel库,并且在面板中使用了imagebutton,但是当我单击imagebutton时什么也没有发生,我在另一个运行良好的活动中尝试了imagebutton。当按下按钮时,“下一个”应该被打印到日志中。我到处搜索,但找不到任何解决方法
这是我的代码:
@SuppressLint("Registered")
public class NowPlaying extends Activity {
ImageButton play, pause, play_main, pause_main, next, imgbtn;
private MusicService musicSrv;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.now_playing);
play = findViewById(R.id.play_button);
imgbtn = findViewById(R.id.imgbtn);
imgbtn.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ShowToast")
@Override
public void onClick(View v) {
Log.i("oladapos", "next");
}
});
SlidingUpPanelLayout now_playing =
findViewById(R.id.slideup_nowplaying);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
playNext();
}
});
}
//play next
private void playNext(){
musicSrv.playNext();
}
//play previous
private void playPrev(){
musicSrv.playPrev();
}
@Override
public void start() {
}
@Override
public void pause() {
}
@Override
public int getDuration() {
return 0;
}
@Override
public int getCurrentPosition() {
return 0;
}
@Override
public void seekTo(int pos) {
}
@Override
public boolean isPlaying() {
return false;
}
@Override
public int getBufferPercentage() {
return 0;
}
@Override
public boolean canPause() {
return false;
}
@Override
public boolean canSeekBackward() {
return false;
}
@Override
public boolean canSeekForward() {
return false;
}
@Override
public int getAudioSessionId() {
return 0;
}
}
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/slideup_nowplaying"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".Fragments.songsFragment">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="@drawable/songs_cover"
tools:ignore="ContentDescription" />
<LinearLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:clickable="true"
android:orientation="horizontal"
android:focusable="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/songs_cover_one"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/songs_cover"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="202dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/linearLayout3"
app:layout_constraintStart_toEndOf="@+id/songs_cover_one"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/songs_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:lines="1"
android:text="@string/havana_camila_cabello_song"
android:textColor="#FFFFFF"
android:textSize="22sp" />
<TextView
android:id="@+id/songs_artist_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:text="@string/camila_cabello" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.974"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:orientation="horizontal">
<Button
android:id="@+id/play_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:clickable="true"
android:focusable="true"
android:scaleType="centerInside"
android:src="@drawable/round_play_arrow_black_48dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/forword_button"
android:id="@+id/imgbtn"/>
</RelativeLayout>
</RelativeLayout>