2012-02-22 4 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가 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

아니요 이미지가 레이아웃의 다른 요소와 겹쳐 야하기 때문에 No입니다. 이 기법을 사용하여 두 개의 단편 레이아웃 사이에 세로 그림자를 넣으려고하지만 그림자는 왼쪽의 요소와 겹쳐 야합니다. – Matroska

+0

'RelativeLayout'은'Linearlayout'을 포함 할 수 있고'LinearLayout'의 모든 속성은 남아 있습니다. 따라서 당신은 아무것도 다시 코딩 할 필요가 없습니다. 그런 다음 Orignal 'LinearLayout' 태그 외부이지만'RelativeLaout' 태그 내부에는 오버레이 요소를 포함하고 오버레이의 각 요소에 대한 위치 ('android : layout_toLeftOf = "@ + id/email")를 지정합니다. – Woodsy

관련 문제