I’m reworking my application, setting some animations. Now basically my Activities are composed
<LinearLayout>
<LinearLayout>
<!-- THE HEADER AND A BUTTON -->
</LinearLayout>
<View>
<!-- A SEPARATION LINE -->
</View>
<ScrollView>
<!-- THE CONTENT -->
</ScrollView>
</LinearLayout>
The animation is always set that the header + the line are pushed in from left, after that the content is pushed in from the button. Now in a specific Activity I saw that the line View was put into the ScrollView (there’s a RelativeLayout in there, since the ScrollView can have only one child).
When I first set the animation (with the line at the wrong place, everything worked):
private void animateHeaderAndContent(){
LinearLayout header = (LinearLayout) findViewById(R.id.overview_lin_0);
header.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in_header));
ScrollView content = (ScrollView) findViewById(R.id.sv_overview_content);
content.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in_content));
}
in xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/overview_lin_0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
(...)
</LinearLayout>
<ScrollView android:id="@+id/sv_overview_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="@+id/rel_over"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<View
android:id="@+id/v_overview_line1"
android:layout_height="1dp"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:background="#FFFFFF"
/>
(...)
As I edited the code and the xml like following, it gives me a ClassCastException at line ScrollView content = (ScrollView) findViewById(R.id.sv_overview_content);, which is exactly the same as before.
in code:
private void animateHeaderAndContent(){
LinearLayout header = (LinearLayout) findViewById(R.id.overview_lin_0);
header.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in_header));
View line = (View) findViewById(R.id.v_overview_line1);
line.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in_header));
ScrollView content = (ScrollView) findViewById(R.id.sv_overview_content);
content.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in_content));
}
in xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/overview_lin_0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<View
android:layout_width="25dp"
android:layout_height="0dp"
/>
<TextView
style="@style/TextHeader"
android:id="@+id/tv_overview_name"
android:layout_width="0dp"
android:layout_weight="8"
android:gravity="center"
android:layout_height="wrap_content"
/>
<ImageButton style="@style/ImageButtonSmall"
android:layout_width="26dp"
android:layout_height="26dp"
android:src="@drawable/ic_action_delete"
android:contentDescription="@string/desc"
android:onClick="onClickDeleteBet"
/>
</LinearLayout>
<View
android:id="@+id/v_overview_line1"
android:layout_height="1dp"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:background="#FFFFFF"
/>
<ScrollView
android:id="@+id/sv_overview_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="@+id/rel_over"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
(...)
How can this be explained (since it is the exaclty same operation in both cases, except that there’s a View in between that should not interfer with a findViewById(...) )?
Probably the references in the
Rclass are not updated correctly. This sometimes happens. Destroy the generatedRfile in eclipse (under the foldergen). Then immediately restart eclipse.Next, select the project and click
Project–>Clean...Then build your application again and the
Rclass will be regenerated.I hope this helps.