android - Unable to set Background in Imagebutton -


here have imagebutton:

  <com.defcomdevs.invento16.squareimageview     android:id="@+id/picture"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_gravity="center_horizontal|top"     android:background="@drawable/custom_button"     android:layout_margin="1dp"     android:scaletype="fitcenter" /> 

squareimageview class extends imagebutton set width , height automatically according screen size.

custom_button.xml:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false">     <shape android:shape="rectangle">         <stroke android:width="5dp" android:color="#885599"/>     </shape> </item> <item android:state_pressed="true">     <shape android:shape="rectangle">         <stroke android:width="8dp" android:color="#802196f3"/>         <gradient android:startcolor="#802196f3" android:endcolor="#802196f3"/>     </shape> </item> 

my problem when set background custom_button image set programmatically overlaps entire area of button.not showing background.otherwise image sets inside button. thing this:

enter image description here

as can see case background=custom_button.

enter image description here

this case otherwise. don't want of these. what want is custom_button set background of imagebutton , src image shown.how da that??please help.thanks.

squareimageview.class:

package com.defcomdevs.invento16;  import android.content.context; import android.util.attributeset; import android.widget.button; import android.widget.imagebutton;  public class squareimageview extends imagebutton {  public squareimageview(context context) {     super(context); }  public squareimageview(context context, attributeset attrs) {     super(context, attrs); }  public squareimageview(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle); }  @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {     super.onmeasure(widthmeasurespec, heightmeasurespec);     setmeasureddimension(getmeasuredwidth(), getmeasuredwidth()); //snap width } } 


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -