In my Android application, I use some image buttons to scroll the ViewFlipper.
My code works fine for all tracks except 1 in some phones (it does not work for Motorola Moto g2 - Android 4.4.4, Samsung Galaxy s2 - Android 4.4.4but works great for Galaxy S3 - Android 4.4.4, Asus Zenfone 5, LG L2and on the emulator).
The code for the snippet is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/exercise_g_background"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.sfcodingteam.psykeappautostima.slidingmenu.fragments.exercise.ExerciseG">
<ImageButton
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@drawable/buttons_exercise_g"
android:contentDescription="@string/Forward"
android:src="@drawable/ic_go_next" />
<ImageButton
android:id="@+id/btnPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/buttons_exercise_g"
android:contentDescription="@string/Back"
android:src="@drawable/ic_go_previous" />
<ImageButton
android:id="@+id/btnAudio"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btnNext"
android:layout_centerHorizontal="true"
android:background="@drawable/buttons_exercise_g"
android:contentDescription="@string/Audio" />
<ViewFlipper
android:id="@+id/viewFlipper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textViewTitleG00"
style="@style/TitleStyle"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/G" />
<TextView
android:id="@+id/textViewG00"
style="@style/TextStyleFirstSentence"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="true"
android:layout_below="@+id/textViewTitleG00"
android:layout_marginTop="25dp"
android:text="@string/ExerciseG00" />
<Button
android:id="@+id/btnStart"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_below="@+id/textViewG00"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:background="@drawable/buttons_exercise_g"
android:text="@string/btnStart"
android:textColor="@android:color/white"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
</ViewFlipper>
</RelativeLayout>
(the fragment contains a lot of content, this is part of it).
This is the initialization of all image buttons:
protected void initializeBtnNext() {
btnNext = (ImageButton) view.findViewById(R.id.btnNext);
if (btnNext == null)
return;
btnNext.setVisibility(View.INVISIBLE);
btnNext.setEnabled(false);
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewFlipper.getDisplayedChild() + 1 < viewFlipper.getChildCount())
goNext();
else getActivity().onBackPressed();
}
});
}
protected void initializeBtnAudio() {
btnAudio = (ImageButton) view.findViewById(R.id.btnAudio);
if (btnAudio == null)
return;
btnAudio.setImageResource(R.drawable.ic_play);
btnAudio.setEnabled(false);
btnAudio.setVisibility(View.INVISIBLE);
btnAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClickBtnAudio();
}
});
}
protected void initializeBtnPrevious() {
btnPrevious = (ImageButton) view.findViewById(R.id.btnPrevious);
if (btnPrevious == null)
return;
btnPrevious.setVisibility(View.INVISIBLE);
btnPrevious.setEnabled(false);
btnPrevious.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goPrevious();
}
});
}
protected void initializeBtnStart() {
btnStart = (Button) view.findViewById(R.id.btnStart);
if (btnStart == null)
return;
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goNext();
}
});
}
Initialization is the same for all fragments (all fragments have btnNext, btnPrevious, btnAudio, and btnStart).
Only btnStart works correctly, while others do not.
Do you have any suggestions?
Edit: found a problem, viewFlipper was enabled by buttons that I was trying to achieve.
,
android:layout_above="@+id/btnNext"
viewFlipper, ! !