私は9パッチのバックグラウンドの問題を見つけました。私が間違っていることを理解できません。奇妙な9パッチの振る舞い
これはボタンのXML構成である。この設定で
<Button android:layout_width="wrap_content" android:id="@+id/buttonBack"
android:layout_alignParentLeft="true" android:layout_centerVertical="true"
android:padding="2dp" android:layout_height="wrap_content"
android:background="@drawable/selector_bg_back_button" android:text="@string/back"
android:textColor="#ffffff" android:textStyle="bold"
android:layout_marginLeft="2dp" />
ボタンが押されたときに背景が異なるように、私は同じ9パッチのみで、(セレクタを使用していグレースケール)。私もセレクタなしで9パッチを直接使ってみましたが、違いはありません。
これは9・パッチ画像です:
そして、これが結果です:あなたが見ることができるように
、パディングとストレッチングエリアは完全に無視されているように見えます。 9パッチ画像をプレーンPNGとして使用しているという印象がありますが、その理由を理解することはできません。これは私の神経に乗り始めているので、どんな助けにも感謝します:p
ありがとうございます。
編集
[OK]をので、これは私がボタンを使用していたフルレイアウトです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent"
android:background="#0ab0ed" android:layout_height="40dip"
android:padding="0px">
<Button android:layout_width="wrap_content" android:id="@+id/buttonBack"
android:layout_alignParentLeft="true" android:layout_centerVertical="true"
android:padding="2dp" android:layout_height="wrap_content"
android:background="@drawable/btn_bg_back_blue" android:text="@string/back"
android:textColor="#ffffff" android:textStyle="bold"
android:layout_marginLeft="2dp" />
<ImageView android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="@drawable/logo"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:padding="10dp" android:layout_height="wrap_content"
android:background="#f5f5f5">
<ImageView android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_centerHorizontal="true"
android:layout_width="wrap_content" android:id="@+id/image" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/txtTitle"
android:textColor="#182973" android:textSize="16dp"
android:textStyle="bold" android:gravity="center_horizontal" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#ffffff">
<TextView android:layout_width="wrap_content"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_height="wrap_content" android:id="@+id/txtDate" style="@style/content" />
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
</RelativeLayout>
とコードワイズ、私はあなたを見ることができますあまりありません。私はすべてのボタンに、非常に簡単なリスナーを追加します:
Button back = (Button) findViewById(R.id.buttonBack);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
これをプロジェクトに挿入します。うまくいった!問題が他の場所にあるように見えますが、より多くのコードを公開できますか? –
投稿を編集して、このボタンを使用する完全なレイアウトとコードを追加しました。あなたが見ることができるように、そこには本当にたくさんのことが起こっているわけではありません。なぜなら、それがうまく動作しないことが奇妙な理由の一部です...私は本当に何も特別なことをしていません。 – Mopper
きれいなビルドを試みましたか?無関係:なぜAndroidデバイスに戻るボタンを実装したいのですか? – Mannaz