1

次の問題があります。Android のドキュメントで指示されているように、RelativeLayout を多用しています。しかし、数日後、理由がわかりません。これはもう機能していません。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/boton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/boton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="60dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

</RelativeLayout>

これは私のレイアウトで、とてもシンプルです。したがって、これによれば、textView はボタンの下にあるはずですが、代わりにボタンの上に表示されます。

結果の写真です.

何が起こったのか誰か説明してくれませんか?

編集:問題は、デバイスで実行しようとしたときではなく、Eclipse用ADTプラグインのグラフィカルレイアウトで表示されたときに発生します...

4

6 に答える 6

2

このコードを試してみると、正しく機能しています。

あなたの側が正しく動作していない場合 プロジェクトをきれいにビルドしてから実行してください。

それでも問題が解決しない場合は、これを試してください

android:layout_below="@+id/boton"

これで上記の行を削除します

android:layout_below="@id/boton"

「+」はR.javaファイルへの新しい参照を作成するため

これが問題かもしれません。

于 2012-10-30T04:54:34.020 に答える
0

drawableプレビューに画像が表示されないため、問題は背景の問題だと思います。

この問題が発生するとbuild error、プレビューにレイアウトが現在の状態で表示されなくなります (最後に成功したビルドに戻ります)。drawableその行を削除して保存してプレビューを表示するか、 s フォルダーに「背景」というタイトルの画像があることを確認してください

ドローアブルなしでこれを試して、それが機能しているかどうかを確認してください。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/boton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/boton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="60dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

</RelativeLayout>
于 2012-10-29T17:25:06.273 に答える
0

TextView のlayout_below属性から「+」記号を取り除きます。「+」は、新しい ID を定義するように指示します。「+」がなければ、既存のものを参照する必要があります。

于 2012-10-29T17:27:14.970 に答える
0

私はそれを実行しようとしていますが、今、何が問題なのかを知っています。

端末でアプリを実行すると、正常に動作しますが、Eclipse の ADT プラグインのグラフィカル レイアウトで表示しようとすると問題が発生します。同じ問題を抱えている人はいますか??

于 2012-10-30T08:54:00.003 に答える
-1

</RelativeLayout>相対レイアウトの最後に追加して、それを閉じます。

于 2012-10-29T17:27:02.933 に答える