2012-02-22 11 views
0

私はAndroidアプリケーションでチュートリアルを作成しようとしていますが、いくつかのUI要素の上にいくつかのバルーンを配置したいと思います。私のUIはLinearLayoutsで構築されています。LinearLayout内の要素にイメージをオーバーラップする方法

LinearLayoutの特定の位置(つまり、id = "@ id/email"のテキストフィールドの横)にフローティング画像を配置するにはどうすればよいですか。

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" > 

    <TextView android:id="@+id/email" 
     style="@style/LoginBarText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="3.0dp" 
     android:text="Email:" /> 
</LinearLayout> 

要素をオーバーラップできるレイアウトは、RelativeLayoutですが、他のレイアウト内の要素に対しては機能しません。

おかげ

+0

LinearLayoutをRelativeLayoutに変更しても問題ありません。 – bhups

+0

%属性で画面を埋めるためにweight属性が必要なので変更できません。 WeightがRelativeLayoutsで機能しない – Matroska

答えて

3

あなたはRelativeLayoutを作成して含めることができ、あなたの元LinearLayout

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

それとも、すぐ隣に画像を追加する必要がある場合(の上ではない)要素は、この方法を試してください。

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:orientation="horizontal"> 

    <ImageView android:id="@+id/image" 
    android:src="@drawable/imagename" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="invisible" /> 

    <TextView android:id="@+id/email" 
    style="@style/LoginBarText" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="3.0dp" 
    android:text="Email:" /> 
</LinearLayout> 

アクティビティコール

image = (ImageView) findViewById(R.id.image); 
image.setVisibility(View.VISIBLE); 
+0

LinearLayout内の要素の隣に画像を描画したい(textViewだけで構成されていない)。私はLinearLayoutsをRelativeLayoutsに置き換えますが、残念ながら、パーセンテージで幅を割り当てるweight属性は、相対レイアウトでは機能しません。 – Matroska

+0

いいえイメージがレイアウトの他の要素と重なっている必要があるためです。私は、このテクニックを使って、2つのフラグメントレイアウトの間に垂直シャドウを配置しようとしていますが、シャドウは左側のエレメントと重なる必要があります。 – Matroska

+0

'RelativeLayout'は' Linearlayout'を含むことができ、 'LinearLayout'のすべてのプロパティは残っています。だからあなたは何かをコード化する必要はありません。次に、Orignalの 'LinearLayout'タグの外側で、' RelativeLaout'タグの中に、あなたのオーバーレイ要素を含み、オーバーレイの各要素の位置( 'android:layout_toLeftOf =" @ + id/email ")を指定します。 – Woodsy

関連する問題