现在的状态:
1.我做了一个selector用来定义按钮显示的状态
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/btn_left_e" />
<item android:state_enabled="true" android:drawable="@drawable/btn_left_n" />
<item android:state_pressed="false" android:drawable="@drawable/btn_left_n" />
<item android:state_pressed="true" android:drawable="@drawable/btn_left_e" />
<item android:state_focused="true" android:drawable="@drawable/btn_left_e" /> <item android:drawable="@drawable/btn_left_n" />
</selector>2.我做了一个LinearLayout里面放了两个按钮
<LinearLayout android:orientation="horizontal" android:gravity="center_vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button android:gravity="left" android:id="@+id/preQuestion" android:layout_weight="1"
android:background="@drawable/btn_left" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:scaleType="center" /> <Button android:gravity="left" android:id="@+id/nextQuestion"
android:layout_toRightOf="@+id/preQuestion" android:layout_weight="1"
android:background="@drawable/btn_right" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:scaleType="center" />
</LinearLayout>现象:
两个按钮被拉伸了,充满了整个LinearLayout,这是我想要的状态。问题:
按钮上的图片同样被拉伸着充满了整个的按钮。
能不能图片不被拉伸,只显示在按钮中间,但按钮的区域被拉伸了?
1.我做了一个selector用来定义按钮显示的状态
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/btn_left_e" />
<item android:state_enabled="true" android:drawable="@drawable/btn_left_n" />
<item android:state_pressed="false" android:drawable="@drawable/btn_left_n" />
<item android:state_pressed="true" android:drawable="@drawable/btn_left_e" />
<item android:state_focused="true" android:drawable="@drawable/btn_left_e" /> <item android:drawable="@drawable/btn_left_n" />
</selector>2.我做了一个LinearLayout里面放了两个按钮
<LinearLayout android:orientation="horizontal" android:gravity="center_vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button android:gravity="left" android:id="@+id/preQuestion" android:layout_weight="1"
android:background="@drawable/btn_left" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:scaleType="center" /> <Button android:gravity="left" android:id="@+id/nextQuestion"
android:layout_toRightOf="@+id/preQuestion" android:layout_weight="1"
android:background="@drawable/btn_right" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:scaleType="center" />
</LinearLayout>现象:
两个按钮被拉伸了,充满了整个LinearLayout,这是我想要的状态。问题:
按钮上的图片同样被拉伸着充满了整个的按钮。
能不能图片不被拉伸,只显示在按钮中间,但按钮的区域被拉伸了?
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/btn_left_e" android:gravity="center_vertical"
android:tileMode="clamp" />
建议楼主用ImageButton吧 图片控制显示区域比较好控制的
如果实在不行,就重写相应的控件,然后添加一个方法,在onDraw()函数中绘制,不要拉伸就行了。