0

ImageView에서 전체 화면 이미지를 표시하고 있으며 ImageView 위에 화면의 중심에 TextView를 추가하려고하지만 TextView가 표시되지 않습니다. ImageView를 통해 TextView 추가 (Android)

내가 시도 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/splash_imageview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="centerCrop" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="20dip" 
     android:background="#AA000000" 
     android:padding="12dip" 
     android:text="SomeText" 
     android:textColor="#ffffffff" /> 

</LinearLayout> 
+2

RelativeLayout 또는 FrameLayout 대신 Linear – Suvitruf

+0

http://stackoverflow.com/questions/19065232/placing-a-textview-on-top-of-imageview-in-android –

답변

2

FrameLayout, AbsoluteLayout (더 이상 사용되지 않음) 또는 RelativeLayout (가장 일반적인 것)을 사용할 수 있습니다. 센터링 RelativeLayout의 예는, 사용 android:layout_centerInParent="true"

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/splash_imageview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerInParent="true" 
     android:scaleType="centerCrop" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="20dip" 
     android:layout_centerInParent="true" 
     android:background="#AA000000" 
     android:padding="12dip" 
     android:text="SomeText" 
     android:textColor="#ffffffff" /> 

</RelativeLayour> 

드로잉 레이아웃 XML과 순서이므로 ImageView 먼저 인출 될 다음 TextView

1

<FrameLayout ...>가 아이의 위에 다른 하나를 그립니다.

배경을 완전히 투명하게 지정할 수 있습니다.

0

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/myImage" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="I am TextView" 
     android:layout_gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

</FrameLayout> 
2

이것을 시도 시도

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/splash_imageview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="centerCrop" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginBottom="20dip" 
     android:background="#AA000000" 
     android:layout_centerInParent="true" 
     android:padding="12dip" 
     android:text="SomeText" 
     android:textColor="#ffffffff" /> 

</RelativeLayout> 
+0

정확히 내가 원했던 것, FrameLayout보다 훨씬 낫다. –

관련 문제