java我想更改单击的任何按钮的大小
我使用了9个按钮,我希望在任何点击的按钮上都更大,如果出现任何退出模式,它们将返回默认状态。 所有这些按钮都在网格布局中使用 我已经使用了9个按钮,我想在任何点击you can see example View in here的人身上变得更大
this is my source code
public class MainActivity extends AppCompatActivity implements Animation.AnimationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
content = 1;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//add category
searchButton = (Button) findViewById(R.id.addCategory);
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final View promptsView = getLayoutInflater().inflate(R.layout.prompts_category, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder.setView(promptsView);
final AlertDialog dialog = alertDialogBuilder.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = 800;
lp.height = 675;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW);
addCategoryButton = (Button) dialog.findViewById(R.id.addCatButton);
insertCategoryName = (EditText) dialog.findViewById(R.id.insertCategoryName);
gridColorsCategory = (GridLayout) dialog.findViewById(R.id.gridColorsCategory);
setSingleEvent(gridColorsCategory);
addCategoryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertCategoryName.getText().toString();
}
});
}
});
}
private void setSingleEvent(GridLayout gridColorsCategory) {
for (int i = 0; i < gridColorsCategory.getChildCount(); i++) {
final Button button = (Button) gridColorsCategory.getChildAt(i);
final int finalI = i;
final ViewGroup.LayoutParams layoutParams = button.getLayoutParams();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
});
}
}
# 1 楼答案
您可以在可绘制文件夹中创建一个xml文件,名为btn_go。如下所示的xml:
然后,在视图的布局中。xml文件,您可以引用按钮的源代码,如下所示:
go_pressed_大图像将略大于go_normal_小图像,通过为宽度和高度指定wrap_内容,按钮应进行调整
# 2 楼答案
您可以使用此方法调整按钮的大小
如果默认值为
wrap_content