2017-06-15 48 views
0

我要添加圖像按鈕,自定義的漣漪效應的圖像按鈕設置連鎖反應。但是如果我改變背景,它會在圖像後面顯示顏色效果。此外,我設置了表格行和圖像按鈕包裝內容,但仍找不到解決方案。 請幫我設置漣漪效果只在圖像按鈕不在外面的空間。如何只對項目的TableRow Android的

<TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="0.5" 
    android:gravity="center_horizontal" 
    android:layout_gravity="center_horizontal" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    > 

    <ImageButton 
     android:id="@+id/ess_btn_leave" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.5" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:src="@drawable/leave" 
     android:background="?android:attr/selectableItemBackground" 
     /> 

    <ImageButton 
     android:id="@+id/ess_imgbtn_expence" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.5" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     android:background="@null" 
     android:src="@drawable/expence" 
     /> 
</TableRow> 
+0

是什麼tagetversion? –

+0

tergetversion- 25 –

+0

你應該有'width'或'height' = 「0dp」 按方向由於使用layout_weight'的'。 –

回答

0

這.XML添加到您的文件夾繪製

<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    android:color="?android:colorControlHighlight"> 
    <item android:drawable="@drawable/button_normal" /> 
</ripple> 

,並以此爲背景,以您的ImageButton的連鎖反應。

+0

我也嘗試過這種方式。但它涵蓋了你再怎麼想連鎖反應應涵蓋整個的ImageButton各地的ImageButton –

+0

@ShuchiSheth後面的ImageButton和效果進行左側和右側的空間? –

+0

我給了我的圖像按鈕0.5重量。我已將圖片縮放類型設置爲fitcenter。所以點擊圖像時,它會在整體佈局上顯示效果。我希望它只是在ImageButton的 –

0

嘗試這種方式

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@android:drawable/ic_button" 
    android:background="?attr/selectableItemBackgroundBorderless" 
/> 
+0

謝謝。但我想添加自定義連鎖效果。如何設置? –

+0

https://stackoverflow.com/questions/24863430/android-ls-ripple-effect-touch-feedback-for-buttons-using-xml –

+0

發佈您的預期輸出屏幕截圖,以便它很容易得到它 –

0

嘗試這種解決方案: -

xml父佈局的下方添加一行: -

android:descendantFocusability="blocksDescendants" 

在ImageButton的在改變顏色根據自己的需要SET-

android:background="@drawable/grid_ripple_effect" 

grid_ripple_effect.xml

<?xml version="1.0" encoding="utf-8"?> 
<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:color="@color/light_green" 
    tools:targetApi="lollipop"> 
    <item android:id="@android:id/mask"> 
     <shape android:shape="rectangle" android:left="-2dp" android:right="-2dp" android:top="-2dp"> 
      <stroke android:width="1dip" android:color="#CABBBBBB" /> 
      <corners android:radius="2dp" /> 
      <solid android:color="@color/light_green" /> 
     </shape> 
    </item> 
</ripple> 
0

您可以在圖像視圖中使用 android:foreground="?attr/selectableItemBackground"。 默認紋波

定製波及您需要創建兩個文件 在你繪製-V21創建一個文件 - 在版本的正常繪製background_ripple.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
android:exitFadeDuration="@android:integer/config_shortAnimTime" 
android:color="@color/lightGrey" > 

<item> 
    <shape android:shape="rectangle" > 
     <solid android:color="@color/white" /> 
    </shape> 
</item> 

以上
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true"> 
     <color android:color="@color/lightGrey" /> 
    </item> 
    <item> 
     <color android:color="@color/white" /> 
    </item> 
</selector> 

,並在你的圖像視圖做android:foreground="@drawable/background_ripple.xml