2011-11-10 6 views
4
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="300dp" 
    android:layout_height="50dp"> 
    <ImageView android:layout_height="40dp" android:id="@+id/imageView1" 
    android:background="@drawable/nicetab" 
    android:layout_width="300dp" ></ImageView> 
    <TextView 
     style="@style/DialogText.Title" 
     android:id="@+id/title" 
     android:paddingBottom="10dip" 
     android:paddingLeft="45dip" 
     android:paddingTop="7dip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@color/codeFont" 
     android:textSize="15dip" 
     /> 
</LinearLayout> 

어떻게 ImageView에 TextView를 삽입 할 수 있습니까? 이 작업을 수행하는 안드로이드에 어떤 방법이 너무 우리가 Z- 인덱스를 사용하여 아라 쉽게,하지만 여기에 HTML에 없다 - 아무 생각안드로이드에서 Z- 인덱스를 사용하는 방법

+1

가능한 복제본 [안드로이드의 다른보기 위의보기 배치/중복 (z- 색인)] (http://stackoverflow.com/questions/4182486/placing-overlappingz-index-a-view-above-another- view-in-android) –

답변

6

아주 간단한 방법은 RelativeLayout

<RelativeLayout 
    android:orientation="vertical" 
    android:layout_width="300dp" 
    android:layout_height="50dp" > 
    <ImageView 
     android:layout_height="40dp" 
     android:id="@+id/imageView1" 
     android:background="@drawable/nicetab" 
     android:layout_width="300dp" /> 
    <TextView 
     style="@style/DialogText.Title" 
     android:id="@+id/title" 
     android:paddingBottom="10dip" 
     android:paddingLeft="45dip" 
     android:paddingTop="7dip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@color/codeFont" 
     android:textSize="15dip" /> 
</RelativeLayout> 
+1

감사합니다. – user989340

2

를 사용하는 것 이미지보기 위에 텍스트보기를 수행하는 방법은 textview의 drawable을 사용하는 것이 좋습니다.

android:drawable[Top|Left|Right|Bottom]="@your_drawable_here" 

<TextView 
    style="@style/DialogText.Title" 
    android:id="@+id/title" 
    android:paddingBottom="10dip" 
    android:paddingLeft="45dip" 
    android:paddingTop="7dip" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/codeFont" 
    android:drawableTop="@drawable/your_drawable_from_imageview" 
    android:textSize="15dip" /> 

나는 당신이 당신의 스타일이 무엇인지 확실하지 않다, 그래서 위에 주어진 어떤 작동하지 않는 경우, 스타일을 제거하는 시도하거나 여기에 스타일을 붙여, 나는 당신을 도울 것입니다.

관련 문제