2014-02-12 5 views
0

У меня есть несколько линейных макетов, расположенных друг над другом, у центра есть изображение. Я пытаюсь получить текст в верхней части изображения в центре, но у меня проблемы. Я пробовал с относительной компоновкой, но это испортило все мои другие макеты. Любые простые решения? EDIT ----Наложение текстового изображения с помощью линейного макета изображения image

<?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" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#000000" 
    android:orientation="horizontal" 
    android:paddingLeft="50dp" 
    android:paddingRight="50dp" > 

    <ImageButton 
     android:id="@+id/btnBck" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@null" 
     android:src="@drawable/ic_launcher" /> 

    <ImageButton 
     android:id="@+id/btnHome" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@null" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="6" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/picPreview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#000000" 
     android:contentDescription="@string/imageDesc" 
     android:src="@null" /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#000000" 
    android:orientation="horizontal" 
    android:paddingLeft="50dp" 
    android:paddingRight="50dp" > 

    <ImageButton 
     android:id="@+id/btnAccept" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@null" 
     android:src="@drawable/ic_launcher" /> 

    <ImageButton 
     android:id="@+id/btnDecline" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="@null" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

</LinearLayout> 

Я пытаюсь получить представление текста поверх/Просмотр изображения picPreview ид

+0

пожалуйста, напишите XML (и код?) – Jim

+0

обновляется с XML – SpunkTrumpet

ответ

3

LinearLayout предназначен для размещения макетов/представлений в ряд (линейно).

Одно решение было бы что-то вроде этого:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="6" 
    android:orientation="vertical" > 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <ImageView 
     android:id="@+id/picPreview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#000000" 
     android:contentDescription="@string/imageDesc" 
     android:layout_centerInParent="true" 
     android:src="@null" /> 
    <TextView 
     android:id="@+id/picPreviewLbl" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerInParent="true" 
     android:text="Overlay" /> 

</RelativeLayout> 
</LinearLayout> 
+0

Я пытался сделать это на некоторое время, необходимо что-то пропустил, потому что это работает. Спасибо за вашу помощь. – SpunkTrumpet

0

Почему бы просто не использовать TextView вместо центрированного ImageView, а затем установить фон текста будет сплошной цвет, который вы сейчас используете? Например.

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:text="Sample Text" ... /> 
+0

Фон не всегда сплошной цвет, он установлен на все, что делает камера. – SpunkTrumpet

+0

В этом случае я бы порекомендовал @Jim ответ – GrouchyPanda

+0

Вот что у меня есть, спасибо за помощь в любом случае. – SpunkTrumpet

Смежные вопросы