1

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

前もって感謝します。

編集

わかりましたので、これはボタンを使用している完全なレイアウトです。

<?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();
        }
    });
4

2 に答える 2

0

ボタンは実際にはそのサイズのように見えますが、背景と内容物のサイズは別のRelativeLayoutことを考えさせます。実際にボタンウィジェットを使用する必要はありません。RelativeLayoutの背景をボタンの背景に設定し、を実装できOnClickListenerます。TextViewとを追加してImageView、希望の外観にします。

于 2011-07-19T09:29:02.530 に答える
0

ボタンとイメージビューの両方で、layout_width が WRAP_CONTENT に設定されているため、元のサイズより大きくなることはなく、9 パッチは引き伸ばされません。

于 2011-07-19T09:33:54.420 に答える