2013-10-04 3 views
0

Основной изюминкой моей деятельности является изображение в центре, которое можно масштабировать до всего экрана. Прямо сейчас, позиции в порядке, но в некоторой точке масштабирования на изображении два текстовых изображения покрываются изображением, остальная часть обзора остается в верхней части изображения.FrameLayout: View Arrangement and Null Pointer Exception

Так что моя главная проблема - разместить два текста в верхней части изображения. Я попытался передать позиции каждого из представлений в xml, но по какой-то причине я получил исключение нулевого указателя.

XML

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

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     android:gravity="center" > 

    <TextView 
     android:id="@+id/txtName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/textView1" 
     android:layout_marginTop="20dp" 
     android:textColor="#FF4F00" 
     android:textSize="20sp" 
     android:alpha=".5" 
     android:text="Name" /> 

    <TextView 
     android:id="@+id/txtPid" 
     android:layout_below="@+id/txtName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:textColor="#FF4F00" 
     android:textSize="20sp" 
     android:layout_marginTop="20dp" 
     android:alpha=".5" 
     android:text="Category Or PID" /> 

    <ImageView 
     android:id="@+id/iv_photo" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:scaleType="center" /> 

    <TextView 
     android:id="@+id/txtItemNo" 
     android:layout_below="@+id/txtSellingPrice" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginTop="19dp" 
     android:textColor="#FF4F00" 
     android:textSize="20sp" 
     android:alpha=".5" 
     android:text="Item No" /> 

    <TextView 
     android:id="@+id/txtSellingPrice" 
     android:layout_below="@+id/txtPid" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginTop="20dp" 
     android:textColor="#FF4F00" 
     android:textSize="20sp" 
     android:alpha=".5" 
     android:text="Selling Price" /> 


    </RelativeLayout> 

</FrameLayout> 

enter image description here

+1

вы можете показать это графически хау это выглядеть или что вы достичь? –

+0

Я добавил снимок экрана – rahstame

ответ

1

Изменение относительного упорядочения вида элемента, так что ImageView является первым элементом. Элементы являются макетом и рисуются в порядке их появления.

0

Попробуйте, как показано ниже:

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" > 
<RelativeLayout 
    android:id="@+id/rl" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <LinearLayout 
     android:id="@+id/layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:orientation="vertical" > 
     <TextView 
      android:id="@+id/txtName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_marginTop="20dp" 
      android:alpha=".5" 
      android:text="Name" 
      android:textColor="#FF4F00" 
      android:textSize="20sp" /> 
     <TextView 
      android:id="@+id/txtPid" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/txtName" 
      android:layout_marginTop="20dp" 
      android:alpha=".5" 
      android:text="Category Or PID" 
      android:textColor="#FF4F00" 
      android:textSize="20sp" /> 
     <TextView 
      android:id="@+id/txtItemNo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/txtSellingPrice" 
      android:layout_marginTop="19dp" 
      android:alpha=".5" 
      android:text="Item No" 
      android:textColor="#FF4F00" 
      android:textSize="20sp" /> 
     <TextView 
      android:id="@+id/txtSellingPrice" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/txtPid" 
      android:layout_marginTop="20dp" 
      android:alpha=".5" 
      android:text="Selling Price" 
      android:textColor="#FF4F00" 
      android:textSize="20sp" /> 
    </LinearLayout> 
    <ImageView 
     android:id="@+id/iv_photo" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentRight="true" 
     android:layout_toRightOf="@+id/layout" 
     android:background="@drawable/selctor" 
     android:scaleType="center" /> 
</RelativeLayout> 
</FrameLayout> 

Выход:

enter image description here

+0

Вложенные макеты ... Вкусный для исполнения пользовательского интерфейса! :) – gunar