2016-12-18 67 views
2

在我的android studio的圖形佈局中,我看到了圖像按鈕上的圖像,但是當我在模擬器上運行我的應用程序時,imagebutton上的圖像沒有得到displayed.I'm安裝的什麼我看到在我的Android工作室,什麼時候我在模擬器上運行我的應用程序,我得到的截圖。 this is what i see on android studio來自ImageButton的圖像沒有在Android Studio的模擬器上顯示

this is what i get on emulator

我還附上我的XML佈局文件

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_calc" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.sameer.coolcalc.CalcActivity" 
tools:background="@android:color/background_light"> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_height="match_parent" 
    android:weightSum="6" 
    android:layout_width="wrap_content"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:background="@android:color/holo_blue_bright" 
     android:weightSum="1"> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:inputType="numberDecimal" 
      android:ems="10" 
      android:id="@+id/editText4" 
      android:text="567" 
      android:textSize="60sp" 
      android:gravity="center_vertical|end" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:weightSum="4"> 

     <Button 
      android:text="7" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button14" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <Button 
      android:text="8" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button13" 
      android:layout_weight="1" 
      android:textSize="36sp" 
      android:textColor="@android:color/black" 
      android:background="@android:color/background_light" /> 

     <Button 
      android:text="9" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button12" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <ImageButton 
      android:layout_height="match_parent" 
      app:srcCompat="@drawable/divide" 
      android:id="@+id/imageButton6" 
      android:layout_weight="1" 
      android:layout_width="match_parent" 
      android:background="@android:color/background_light" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <Button 
      android:text="4" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button3" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <Button 
      android:text="5" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button2" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <Button 
      android:text="6" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <ImageButton 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:srcCompat="@drawable/multiply" 
      android:id="@+id/imageButton" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" /> 

    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:weightSum="4"> 

     <Button 
      android:text="1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button6" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <Button 
      android:text="2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button5" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <Button 
      android:text="3" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/button4" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <ImageButton 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:srcCompat="@drawable/subtract" 
      android:id="@+id/imageButton3" 
      android:layout_weight="1" 
      android:background="@android:color/background_light" /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_height="match_parent" 
      android:background="@android:color/background_light" 
      android:layout_width="205dp" 
      android:gravity="center"> 

      <Button 
       android:text="clear" 
       android:id="@+id/button15" 
       android:background="@android:color/holo_blue_bright" 
       android:layout_width="170dp" 
       android:layout_height="50dp" 
       android:textSize="30sp" /> 
     </LinearLayout> 

     <Button 
      android:text="0" 
      android:layout_height="match_parent" 
      android:id="@+id/button11" 
      android:layout_width="103dp" 
      android:background="@android:color/background_light" 
      android:textColor="@android:color/black" 
      android:textSize="36sp" /> 

     <ImageButton 
      android:layout_width="103dp" 
      android:layout_height="match_parent" 
      app:srcCompat="@drawable/add" 
      android:id="@+id/imageButton5" 
      android:background="@android:color/background_light" /> 
    </LinearLayout> 

</LinearLayout> 

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/equal" 
    android:id="@+id/imageButton7" 
    android:background="@android:color/transparent" 
    android:layout_alignParentEnd="true" 
    android:layout_marginTop="140dp" /> 
</RelativeLayout> 
+0

使用Android:SRC,而不是應用程序:srcCompat – AndroidRuntimeException

+0

@AgustinSivoplás是啊,是工作,但我沒有得到機器人之間的區別:src和應用程序:你srcCompat.Can plzz解釋一下嗎? –

回答

2

使用Android:SRC,而不是應用程序:srcCompat.This將解決你的問題現在。

應用:srcCompat來自Android的支持庫,也支持向量繪圖資源和矢量動畫可繪製。

如果你想使用的應用程序:srCompat你應該配置gradle這個。

android { 
    defaultConfig { 
    vectorDrawables.useSupportLibrary = true 
    } 
} 

當使用程序兼容性與ImageView的(或子類,如ImageButton的 和FloatingActionButton),你就可以使用新的應用程序:srcCompat 屬性來引用矢量繪圖資源(以及任何其他可繪製 可到Android:SRC)

此處瞭解詳情:https://android-developers.googleblog.com/2016/02/android-support-library-232.html

相關問題