button background图片被拉伸
问题:
<Button
android:id="@+id/recitebrowse_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/activity_head_title_margin_left"
android:background="@drawable/newwordrecitebrowse_left_background"
android:onClick="onClick" >
</Button>
结果是,button的背景图片被拉伸!
解决方法:
方法一:
把layout_width和layout_height设置为固定值。如:
<Button
android:id="@+id/recitebrowse_left"
android:layout_width="14dp"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/activity_head_title_margin_left"
android:background="@drawable/newwordrecitebrowse_left_background"
android:onClick="onClick" >
</Button>
方法二:把Button改为ImageButton或者ImageView.
方法三:在Button的属性里增加android:minHeight="0dp"和android:minWidth="0dp"。如:
<Button
android:id="@+id/recitebrowse_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/activity_head_title_margin_left"
android:background="@drawable/newwordrecitebrowse_left_background"
android:minHeight="0dp"
android:minWidth="0dp"
android:onClick="onClick" >
</Button>
个人建议采用方法三!