奇妙な問題があります。から継承するクラスがありRelativeLayout
ます。私はxmlに膨らませます。このレイアウトのデフォルトの背景画像はxmlに設定されており、実行時に変更しようとしています。
if(event.getAction() == MotionEvent.ACTION_DOWN) {
System.out.println("Action down");
this.setBackgroundResource(R.drawable.event_cell_selected);
}
else if(event.getAction() == MotionEvent.ACTION_CANCEL) {
System.out.println("Action down");
this.setBackgroundResource(R.drawable.event_cell);
}
リソースevent_cell
とevent_cell_selected
は両方とも .png ファイルです。また、ログが表示されます。ここで何が起こっているのか、私には本当に言えません。
[編集] 素早い回答ありがとうございます。logcat にエラーはありません。膨らませた xml は次のとおりです。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/event_cell"
android:paddingBottom="@dimen/padding_small"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:paddingTop="@dimen/padding_large" >
<TextView
android:id="@+id/textViewMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="juil."
android:textColor="@color/event_header"
android:textSize="19dp"
android:textStyle="bold" />
<TextView
android:id="@+id/textViewDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewMonth"
android:layout_marginBottom="@dimen/margin_small"
android:text="TextView"
android:textColor="@color/event_header"
android:textSize="15dp" />
<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="TextView"
android:textColor="@color/event_header"
android:textSize="17dp" />
<ImageView
android:id="@+id/imageViewSeparator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textViewDay"
android:layout_marginBottom="@dimen/margin_small"
android:src="@drawable/event_title_descr_separator" />
<TextView
android:id="@+id/textViewDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageViewSeparator"
android:ellipsize="end"
android:maxLines="2"
android:text="TextView"
android:textColor="@android:color/black"
android:textSize="12dp" />
そして、ここに私のルートxmlがあります:
<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" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/navigationBarView" >
<LinearLayout
android:id="@+id/eventsLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/margin_small"
android:paddingRight="@dimen/margin_small" >
</LinearLayout>
</ScrollView>
膨張した RelativeLayout が scrollView の linearlayout に追加されます
[編集] この問題を解決するために、最終的にデフォルトの背景画像をプログラムで (xml ではなく) 設定することになりました。それはトリックを行います。Androidは本当に奇妙な動作をすることがあります...