2012-02-15 2 views
1

私はアンドロイドの開発者として非常に新しく、現在RelativeLayoutを理解していますが、Textviewがイメージ上にオーバーラップする小さな問題に直面しています。ここで私はあなたに、私が何を望んでいるのか、私が何を得ているのか、私が多くしているコードを提供しています。だから私を助けてください。相対レイアウトRelativeLayoutコンポーネントで宣言されたコンポーネントをオーバーレイします

<RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/firstImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/splash1" /> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/firstImage" 
     android:layout_alignBaseline="@id/firstImage" 
     android:text="@string/menu" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/splash1" /> 
</RelativeLayout> 

ここではレイアウトに必要な画像を示します。

enter image description here

私を助けてください。

事前に感謝..

+0

私はLinearLayoutを使用します。 http://developer.android.com/resources/tutorials/views/hello-linearlayout.html – Sparky

答えて

3

このコード

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

<ImageView 
    android:id="@+id/firstImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/logo2"/> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/logo2" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"  
    android:layout_centerHorizontal="true"  
    android:layout_centerVertical="true"  
    android:text="menu" /> 

..テキストビューのために

android:layout_centerHorizontal="true"  
android:layout_centerVertical="true" 

チェックをこれらのプロパティを使用します

+0

Raja Great Answerありがとう –

1

2以上のTextView android:layout_centerHorizontal="true"のproperitiesとandroid:gravity="center"を追加し、そのテキストがyoutはTextViewの内側にセンタリングされます。

テキストが大きすぎる(画像に重なる)場合は、この問題が発生する可能性があります。そのようなレイアウトを定義するのを避けるには:

<RelativeLayout 
android:id="@+id/relativeLayout1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 
    <ImageView 
    android:id="@+id/firstImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/splash1" 
    /> 
    <ImageView 
    android:id="@+id/secondImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/splash1" 
    /> 
    <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignTop="@id/firstImage" 
    android:layout_alignBottom="@id/firstImage" 
    android:layout_toRightOf="@id/firstImage" 
    android:layout_toLeftOf="@id/secondImage" 
    android:gravity="center" 
    android:text="@string/menu" 
    /> 
</RelativeLayout> 

TextViewの前に両方のイメージビューが定義されていることに注意してください。これらの画像ビューはアンカービューになり、他のすべての画像ビューはそれらに応じて配置されるためです。あなたのTextViewは2つのImageViewの間にあるので、テキストが何であっても重なり合うことはありません。

1

これであなたのxmlファイルのコードを置き換え...

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

    <ImageView 
     android:id="@+id/firstImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/splash1" /> 

    <ImageView 
     android:id="@+id/firstImage2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/splash1" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toLeftOf="@+id/firstImage2" 
     android:layout_toRightOf="@+id/firstImage" 
     android:text="@string/menu" /> 

</RelativeLayout> 
1

グラフィックモードに切り替えて上記を修正することができます。 XMLですべてのものを直接定義する必要はありませんが、グラフィックモードに切り替えてこれを修正することができます。

関連する問題