2016-06-28 54 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> 

道歉,如果這符合資格重複的問題。

編輯: 該活動的屏幕截圖。

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或者和Google Checkout,這個網站: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. 的Invalidate緩存和重新啓動的Android工作室,或者只是重新啓動,同時又不會使

  2. 嘗試Run -> Clean and rerun選項

  3. 還是Build -> Clean projectBuild -> Rebuild Project選項

完成後,再次運行項目。

0

嗯,我懂了工作,我也解釋不清楚什麼固定的,但這些是我所採取的步驟:

  1. 利用的內容和活動分裂。 (以獲得一個這樣的例子在android studio中創建一個基本的活動)。
  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>