0

いくつかのアニメーションを設定して、アプリケーションを作り直しています。今、基本的に私の活動は構成されています

<LinearLayout>
    <LinearLayout>
        <!-- THE HEADER AND A BUTTON -->
    </LinearLayout>
    <View>
        <!-- A SEPARATION LINE -->
    </View>
    <ScrollView>
        <!-- THE CONTENT -->
    </ScrollView>
</LinearLayout>

アニメーションは常に左からヘッダー+行を押し込み、その後ボタンからコンテンツを押し込む設定になっています。ここで、特定Activityの行Viewが に配置されていることがわかりましたScrollView( には子が1つしかないRelativeLayoutため、そこに があります)。ScrollView

最初にアニメーションを設定したとき (線が間違った場所にあると、すべてが機能しました):

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));
}

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"
                    />

                (...)

ScrollView content = (ScrollView) findViewById(R.id.sv_overview_content);次のようにコードと xml を編集すると、以前とまったく同じ行で ClassCastException が発生します。

コードで:

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));
}

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"        
            >
            (...)

これはどのように説明できますか (どちらの場合もまったく同じ操作ですがView、間に a と干渉してはならないことを除いてfindViewById(...))?

4

1 に答える 1

1

クラス内の参照がR正しく更新されていない可能性があります。これは時々起こります。R生成されたファイルを Eclipse で破棄します (フォルダーの下gen)。その後、すぐにEclipseを再起動します。次に、プロジェクトを選択してProject-->をクリックClean... し、アプリケーションを再度ビルドすると、Rクラスが再生成されます。

これが役立つことを願っています。

于 2012-10-27T15:41:15.953 に答える