2016-09-25 78 views
1

在我的佈局文件中,對於最後一個線性佈局,我添加了三個帶有有效圖像和文本的圖像按鈕。但是他們根本沒有在應用程序中顯示。下面給出了這個佈局文件。沒有在imageButtons中獲取圖像

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="120dp" 

    android:background="?android:attr/selectableItemBackground" 
    android:clickable="true" 
    android:focusable="true" 
    android:orientation="vertical"> 

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

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:srcCompat="@drawable/female_default" 
      android:layout_gravity="center_horizontal" 
      android:id="@+id/imageView2" 
      android:layout_weight="1" /> 

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

      <TextView 
       android:text="TextView" 
       android:layout_gravity="center_horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/textView3" /> 

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

       <TextView 
        android:text="TextView" 
        android:layout_gravity="center_horizontal" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/textView2" /> 

       <TextView 
        android:id="@+id/id" 
        android:layout_gravity="center_horizontal" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_margin="@dimen/text_margin" 
        android:text="Balle" 
        android:textAppearance="?attr/textAppearanceListItem" /> 

       <TextView 
        android:id="@+id/content" 
        android:layout_gravity="center_horizontal" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_margin="@dimen/text_margin" 
        android:text="Shaaba" 
        android:textAppearance="?attr/textAppearanceListItem" /> 
      </LinearLayout> 

     </LinearLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="100dp"> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      app:srcCompat="@android:drawable/ic_menu_edit" 
      android:id="@+id/imageButton4" 
      android:layout_weight=".25" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      app:srcCompat="@android:drawable/ic_menu_delete" 
      android:id="@+id/imageButton3" 
      android:layout_weight=".25" /> 

     <Button 
      android:text="@string/mark_as_default" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/button" 
      android:layout_weight=".5" /> 
    </LinearLayout> 

</LinearLayout> 

Given is the snapshot of the image. As you can see, below the circular image all the three buttons are not visible at all.

回答

0

變化

android:srcCompat="drawable/ic_menu_edit" 

app:srcCompat="drawable/ic_menu_edit" 

srcCompat是程序兼容性庫的屬性。

0

看來你正在嘗試使用內置的Android資源。所以,你需要做以下的 ImageButton的圖像源的變化:

//改變這種

<ImageButton android:src="@drawable/ic_menu_delete"/> 

//這個

<ImageButton android:src="@android:drawable/ic_menu_delete"/> 

請務必更改此語法在所有的圖像按鈕srcCompat屬性,它應該工作。

如果你在你的項目中那些圖標複製可繪製文件夾,然後@繪製/ ic_menu_delete語法將工作

請讓我知道,如果這是任何幫助。

+1

即使在這些變化之後它仍然不工作:( –

+0

使用android:src而不是android:srcCompat並重試。 –

0

基本上,原因是LinearLayout的父LinearLayout中的第一個LinearLayout的layout_height爲「match_parent」。由於這個原因,它抑制了包含三個ImageButton的LinearLayout。將其更改爲wrap_content使其正常工作。

android:focusable="true" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
相關問題