2015-09-02 5 views
0

Я сделал простое приложение для камеры и думал о настройке вида. В настоящее время у меня возникла проблема с тем, что ImageView не может отображаться в верхней части рамки. Что-то не так с кодом xml ниже? Или я должен установить некоторый параметр в коде? Все, что я хочу сделать, это отобразить изображение над рамкой.Невозможно отобразить ImageView в FrameLayout (Android)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <FrameLayout 
     android:id="@+id/camera_preview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 

     <LinearLayout 

      android:orientation="horizontal" 

      android:layout_width="wrap_content" 

      android:layout_height="match_parent" 

      android:layout_gravity="right|center_vertical"> 
     <ImageView 
      android:id="@+id/button_capture" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/shot_dot_icn" /> 
      </LinearLayout> 
    </FrameLayout> 
</LinearLayout> 
+0

У вашего кода есть ImageView внутри FrameLayout, а не на нем. –

+0

Вам нужно уточнить, чего вы пытаетесь достичь. Нарисуйте эскиз или что-то еще. Вы макет не имеет смысла. Почти все макеты в вашем текущем XML бесполезны. И замените fill_parent на match_parent, заполнение устарело. – Kenneth

ответ

0

Пробуйте этот макет, я не уверен, что я понимаю ваше требование.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
     <ImageView 
      android:id="@+id/button_capture" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/shot_dot_icn" /> 
    <FrameLayout 
     android:id="@+id/camera_preview" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     > 

     <LinearLayout 

      android:orientation="horizontal" 

      android:layout_width="wrap_content" 

      android:layout_height="match_parent" 

      android:layout_gravity="right|center_vertical"> 
      </LinearLayout> 
    </FrameLayout> 
</LinearLayout> 
0

Я решил проблему со сценарием ниже. Все, что мне нужно было сделать, - установить для функции showToFront() в ImageView, чтобы установить представление поверх Framelayout.

ImageView captureButton = (ImageView) findViewById(R.id.button_capture); 
     captureButton.bringToFront(); 
Смежные вопросы