2016-06-28 2 views
0

Я пытаюсь показать кнопку над полноэкранным изображением. I tried to use RelativeLayout, как показано в этом вопросе, но я не вижу кнопку.Не удается увидеть кнопку над полноэкранным представлением Imageview

Может кто-нибудь сказать мне, почему этот код не работает?

<RelativeLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/pitchImageView" 
     android:src="@drawable/gaa_pitch" 
     android:scaleType="centerCrop"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/start" 
     android:id="@+id/stopwatchButton" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true"/> 
</RelativeLayout> 

Извините, если это относится к дубликатному вопросу.

EDIT: Скриншоты деятельности.

Android design tab

Emulator at runtime

+1

Вы можете разместить снимок экрана из него? –

ответ

0
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/pitchImageView" 
     android:src="@drawable/gaa_pitch" 
     android:scaleType="centerCrop"/> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/start" 
     android:id="@+id/stopwatchButton" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true"/> 

</RelativeLayout> 
0

Мой друг вы можете использовать FrameLayout в качестве альтернативы, и проверка этого сайта: Android Frame Layout

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/pitchImageView" 
    android:src="@drawable/desert_road" 
    android:scaleType="centerCrop"/> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Start" 
    android:src="@drawable/ic_clear_white_24dp" 
    android:id="@+id/stopwatchButton" 
    android:layout_gravity="center" /> 
</FrameLayout> 

Результат:

enter image description here

0

Это обычная проблема. Вы можете попробовать несколько вещей:

  1. ТЕРЯЮТСЯ кэша и перезапустить Android Studio, или просто перезагружать без недействительности

  2. Попробуйте Run -> Clean and rerun вариант

  3. или Build -> Clean project или Build -> Rebuild Project вариант

Когда все будет готово, запустите проект еще раз.

0

Ну, я получил это работает, я не могу точно объяснить, что установил его, но это шаги, которые я взял:

  1. Использовано раскол содержания и активности. (чтобы получить пример этого, создайте базовую активность в студии android).
  2. Я удалил другие версии файлов макета в папках, совместимых с версией (например, «layout-v24»).
  3. Я также использовал опции «Очистить» и «Перестроить», когда я вносил изменения в свой код.

активность XML файл:

<android.support.design.widget.CoordinatorLayout 
    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:fitsSystemWindows="true"> 

    <include layout="@layout/content_record_game"/> 
</android.support.design.widget.CoordinatorLayout> 

Это мой content.xml файл

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

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/pitchImageView" 
    android:contentDescription="@string/image_of_a_gaa_pitch" 
    android:src="@drawable/gaa_pitch" 
    android:scaleType="centerCrop" 
    android:cropToPadding="false" 
    /> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/start" 
    android:id="@+id/stopwatchButton" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 
</RelativeLayout> 
Смежные вопросы