1

次のレイアウトがあります

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:background="@drawable/flowerpower">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_y="200dip"
            android:textColor="#000000"
            android:text="Test"/>
</AbsoluteLayout>

現在、異なる画面サイズのディスプレイでは、絶対レイアウトであるため、TextView が正しい位置にないという問題があります。これを RelativeLayout で機能させるにはどうすればよいですか? これが正しい解決策だと思いますか?RealtiveLayout?

4

4 に答える 4

1

まずはAbsolute LayoutAndroid SDKで非推奨になっているので使わないようにしましょう。

コードの2番目に、これを試してください:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:background="@drawable/flowerpower">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textColor="#000000"
            android:text="Test"/>
</RelativeLayout>

これにより、テキストビューが画面の右側に配置されます。画面の右側にマージンを置きたい場合は、テキストビューで次のコードを使用することもできます。

android:layout_marginRight="10dip"
于 2011-05-20T09:53:27.507 に答える
0

これを試して :

<RelativeLayout android:id="@+id/Layout01"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/flowerpower">

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:textColor="#000000"
        android:text="Hello world !!"/>
</RelativeLayout>

注意:このリンクをたどってください

于 2011-05-20T10:06:22.343 に答える
0

このような単純なレイアウトには、LinearLayoutを使用します。ただし、Android Layout Documentationを確認する必要があります。

于 2011-05-20T09:52:30.430 に答える