Android:布局->;按钮选择器->;按钮没有变小
所以我有这个问题。我制作了一个按钮和一个.xml按钮选择器文件,除了一件事之外,一切都很好 我希望发生什么:当您单击(或选择)按钮时,按钮会变小(准确地说,它会变为更小的.png文件) 发生了什么:当您单击(或选择)按钮时,按钮不会变小,而是会拉伸以适合家长(总之,大小保持不变)。我认为这与错误的布局参数有关。你能帮我吗?下面是一些代码:Android:布局->;按钮选择器->;按钮没有变小,android,button,size,selector,Android,Button,Size,Selector,所以我有这个问题。我制作了一个按钮和一个.xml按钮选择器文件,除了一件事之外,一切都很好 我希望发生什么:当您单击(或选择)按钮时,按钮会变小(准确地说,它会变为更小的.png文件) 发生了什么:当您单击(或选择)按钮时,按钮不会变小,而是会拉伸以适合家长(总之,大小保持不变)。我认为这与错误的布局参数有关。你能帮我吗?下面是一些代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/listbg"
android:paddingTop="110dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ScrollView
android:id="@+id/scrollView1"
android:layout_height="fill_parent"
android:layout_width="wrap_content">
<RelativeLayout
android:id="@+id/linearLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal">
<Button android:layout_height="wrap_content"
android:id="@+id/Button1"
android:background="@drawable/placestovisit"
android:state_pressed="true"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"/>
<!-- This is the button I am talking about -->
<Button android:layout_height="wrap_content"
android:id="@+id/Button2"
android:background="@drawable/mostpopular_button"
android:layout_width="wrap_content"
android:layout_below="@+id/Button1"/>
将此添加到所有按钮:
android:onClick="doButtonAction"
在按钮布局的活动中执行此操作
public void doButtonAction(View view)
{
Button yourButton = (Button)findViewById(view.getId());
yourButton.setScaleX(.8);
yourButton.setScaleY(.8);
//do button stuff here
}
如果这本身不起作用,可以尝试明确设置按钮的高度和宽度,例如:
android:layout_height="50px"
android:layout_width="150px"
在这种情况下,避免使用包裹内容可能会阻止拉伸