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