2

私は、Wallace Jackson の「Android Apps for Absolute Beginners」、第 3 版から作業しています。

現在、第 9 章 (p. 350) の最後にあります。

リソース ディレクトリの PNG ファイル、imagebutton 状態ファイル、およびメイン アクティビティのレイアウトを更新しました。本のコードサンプルのほとんどはそのままではうまくいかないので、驚くべきことではありませんが、これには少し困惑しています。イメージ ボタンは、スライド ペイン レイアウトの左側のペインに表示されません。画像があるはずの場所に 3 つの小さな白い四角形が見えますが、それらは正方形でなければなりません (まあ、円ですが、技術的には画像は透明な正方形のままです)。銀河の小さな写真もあるはずです。

Androidスタジオはエラーを出さず、状態ファイルには適切なボタン状態リソースを示すサムネイルさえあります.

JRE 1.7.0_71 で AndroidStudio 1.1.0 を使用しています。Android 5.1 を搭載した Google Nexus 7 でデバッグしています

ボタン状態ファイル (stackoverflow が終了セレクター タグを難読化していることに注意してください)

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_hovered="true" android:drawable="@drawable/imagebutton1hover" />
<item android:state_pressed="true" android:drawable="@drawable/imagebutton1press" />
<item android:state_focused="true" android:drawable="@drawable/imagebutton1focus" />
<item android:drawable="@drawable/imagebutton1normal" />

レイアウトファイル

<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/spLayout"
android:background="@drawable/ninepatchframe">
<LinearLayout
    android:layout_width="110dp"
    android:layout_height="match_parent"
    android:layout_weight="0.25"
    android:orientation="vertical">
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyOne"
        android:src="@drawable/ibstates1"
        android:contentDescription="@string/galaxyone"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyTwo"
        android:src="@drawable/ibstates2"
        android:contentDescription="@string/galaxytwo"/>
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/galaxyThree"
        android:src="@drawable/ibstates3"
        android:contentDescription="@string/galaxythree"/>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@drawable/galaxyinfoscreen">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#00000000"
        android:layout_margin="12dp">
        <TextView
            android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="48dp" android:textStyle="bold"/>
        <TextView
            android:text="@string/galaxy_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF" />
        <TextView
            android:text="@string/galaxy_solar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_habit"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_colony"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_pop"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_fleet"
            android:textColor="#FFFFFF" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/galaxy_ships"
            android:textColor="#FFFFFF" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#00000000"
        android:layout_marginTop="33dp">
        <TextView
            android:text="@string/name_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:id="@+id/name"/>
        <TextView
            android:text="@string/solar_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:id="@+id/solar"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/habit_data"
            android:textColor="#FFFFFF"
            android:id="@+id/habit"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/colony_data"
            android:textColor="#FFFFFF"
            android:id="@+id/colony"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/pop_data"
            android:textColor="#FFFFFF"
            android:id="@+id/pop"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/fleet_data"
            android:textColor="#FFFFFF"
            android:id="@+id/fleet"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ships_data"
            android:textColor="#FFFFFF"
            android:id="@+id/ships"/>
    </LinearLayout>
</LinearLayout>

別の奇妙なこと...それが関連しているとは思わないが、誰が知っている. 本のスクリーン ショットでは、スライディング ペイン パネル全体の周りに 9 つのパッチ パネルが表示されていますが、私のアプリケーションでは、9 つ​​のパッチは右側のパネルで完全に覆われています (右側のパネルではまったく見えません)。

何かご意見は?

4

1 に答える 1

0

回答はすでに他の人によって投稿されています。彼にとって残念なことに、リンクされた投稿の OP は、PSIXO からの正しい答えを決して認めませんでした。

Androidスタジオエラーレンダリングのセレクター付きの画像ボタン

スレッド全体を読みたくない方のために、物理ファイル名は「.xml」で終わる必要があります。Android プログラミングに関する本では、「ibstates」という名前のファイルを作成するように読者に指示していますが、名前は「ibstates.xml」でなければなりません。そうしないと、リソースとして参照すると Android Studio が壊れて終了します。

于 2015-04-29T01:55:41.440 に答える