2015-04-23 77 views
0

我使用下面的代码设计了圆形按钮,然后我想在按钮上显示一些文本,所以我使用了框架布局,然后在我的按钮上放置了一些文本。 现在Challange是我的按钮仍然是。它没有显示任何影响点击 其中drawable和src都用于圆形按钮和其他按钮上的图像(respectivitly)。如何在Imagebutton上点击

现在我的按钮不会对设计产生任何影响,请点击我如何实现该效果。

<FrameLayout> 
<ImageButton 
android:id="@+id/btn_profile_view" 
android:layout_width="70dp" 
android:layout_height="67dp" 
android:layout_marginLeft="20dp" 
android:layout_marginRight="20dp" 
android:layout_marginTop="20dp" 
android:layout_weight="1" 
android:onClick="compareButtonClick" 
android:background="@drawable/roundedbutton" 
android:src="@drawable/ic_action_person" /> 
<TextView 
android:layout_width="45dp" 
android:layout_height="20dp" 
android:layout_gravity="bottom" 
android:layout_marginLeft="38dp" 
android:clickable="false" 
android:text="@string/profile" 
android:textColor="@color/btn_txt" > 
</TextView> 
</FrameLayout> 


<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 

<solid android:color="#D3D3D3" /> 

<corners 
    android:bottomLeftRadius="8dip" 
    android:bottomRightRadius="8dip" 
    android:topLeftRadius="8dip" 
    android:topRightRadius="8dip" /> 

+0

为什么你还没有指定framelayout尺寸属性? – Abhishek

+0

并显示你的代码,你正在试图获得onclick回拨 – Abhishek

+0

我不需要框架布局属性,因为我把我的框架布局放在表格布局中,表格行布局和我在重量单行上使用重量显示3图像按钮表行中的属性。 – user3719634

回答

0

在这里,你会得到你的点击回电,你不需要设置点击收听任何地方

public void compareButtonClick(View v){ 
    Toast.makeText(this, "Image Button Click", Toast.LENGTH_SHORT).show(); 
} 
0

这可能会帮助,但你必须修改它以满足您的需要。

1)drawable文件夹

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 

<solid android:color="#D3D3D3" /> 

<corners 
    android:bottomLeftRadius="8dip" 
    android:bottomRightRadius="8dip" 
    android:topLeftRadius="8dip" 
    android:topRightRadius="8dip" /> 
</shape> 

2)创建button_normal.xmldrawable文件夹

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item android:drawable="@drawable/roundedbutton" android:state_focused="true" android:state_pressed="true"/> 
    <item android:drawable="@drawable/ic_launcher" android:state_focused="false" android:state_pressed="true"/> 
    <item android:drawable="@drawable/ic_launcher" android:state_focused="true"/> 
    <item android:drawable="@drawable/roundedbutton" android:state_focused="false" android:state_pressed="false"/> 

    <!-- 2 and 3 pressed and selected --> 


</selector> 

3)作为背景添加button_normal.xml到您的按钮

android:background="@drawable/button_normal" 
0

创建创建roundedbutton.xml选择器wi处理不同状态的不同drawables;启用,禁用,点击,专注等