2016-03-09 55 views
0

我的應用程序是這樣的:如何去除我的圖像按鈕周圍的白色填充?

enter image description here

我想我的兩個圖像按鈕完全填補我的LinearLayout的空間,該複選框的方式做 - 他們沒有周圍的白色填充。我嘗試了很多東西建議在stackoverflow =使背景「@null」等,但沒有一個工作。

我想我可以嘗試一個ImageView,但我想要有'點擊'效果。

任何想法?這是我的代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="0dp" 
    android:paddingLeft="0dp" 
    android:paddingRight="0dp" 
    android:paddingTop="0dp" 
    tools:context=".MainActivity"> 

    <ListView 
     android:id="@+id/ListView_2" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:layout_weight="1"> 
    </ListView> 


    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:id="@+id/editText" 
     android:gravity="center" 
     android:inputType="phone" 
     android:background="#d9d9d9"> 
    </EditText> 



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

    <CheckBox 
     android:layout_height="match_parent" 
     android:layout_width="wrap_content" 
     android:background="#ffa500" 
     android:text="New CheckBox" 
     android:id="@+id/checkBox" 
     android:layout_weight="2" 
     > 
    </CheckBox> 

     <ImageButton 
      android:layout_height="match_parent" 
      android:layout_width="wrap_content" 
      android:id="@+id/imageButton" 
      android:layout_gravity="center_horizontal" 
      android:layout_weight="1" /> 

     <ImageButton 
      android:layout_height="match_parent" 
      android:layout_width="wrap_content" 
      android:id="@+id/imageButton2" 
      android:layout_gravity="center_horizontal" 
      android:layout_weight="1" /> 

    </LinearLayout> 

</LinearLayout> 

回答

0

請您的ImageView backgrouund設置爲透明並設置在SRC顏色或繪製。類似這樣的:

<ImageButton 
     android:layout_height="match_parent" 
     android:layout_width="wrap_content" 
     android:id="@+id/imageButton" 
     android:background="@android:color/transparent" 
     android:src="?colorPrimary" 
     android:layout_gravity="center_horizontal" 
     android:layout_weight="1" /> 
+0

解決了上述問題沒問題。但實際上我需要在imagebutton上放置一個圖像。我希望按鈕看起來像已被按下 - 我想圖像是相同的,但要更改的按鈕的背景顏色。看起來我需要使用一個selector.xml。 – CHarris

+0

是的。您可以使用具有某種形狀或圖層列表的選擇器。 – Srijith