android - 按下按钮时如何增加按钮大小?请帮我
问题描述
请帮我这样做,当我按下按钮时,按钮大小会增加。我会给截图。我还将分享一些按钮代码
<Button
android:id="@+id/sbi_button"
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="10dp"
android:layout_marginTop="40dp"
android:backgroundTint="#1B79E6"
android:gravity="center"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
android:padding="12dp"
app:icon="@drawable/ic_sbi"
app:iconPadding="0dp"
app:iconSize="17dp"
app:iconTint="#FFFFFF"
app:layout_constraintEnd_toStartOf="@id/axis_button"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toBottomOf="@id/transfer_textView"
app:rippleColor="@android:color/transparent"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.MyApp.Button.Circle"
app:strokeWidth="0dp" />
解决方案
您可以使用其更改Button
(或任何其他View
)的大小LayoutParams
// obtaining reference to view, e.g. in Activity
Button b = findViewById(R.id.sbi_button);
// setting new size
int newSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60,
getResources().getDisplayMetrics()); // 60dp to px unit
b.getLayoutParams().width = newSize; // setting new width and height
b.getLayoutParams().height = newSize;
b.requestLayout(); // force remeasure and redraw, may not be needed
推荐阅读
- android - Android 中 SingleThreadExecutor 和 Handler 之间的区别(通过示例)
- robotframework - 数据未写入 Excel 文件,Robot 框架中未引发错误
- asp.net-identity - 使用 Azure AD 的 ASP .NET Core 3.1 Windows 身份验证
- git - 重置为默认目录 vscode
- r - 自cross接管mutate_at以来更新fct_relevel解决方案
- php - 如何使用 file_get_contents() 读取上传的图片?
- java - 调用更新数据时出现异常
- amazon-web-services - 如何将域中的多个路径重定向到不同的 AWS 负载均衡器?
- css - 为什么 tspan 位置错误地超过 200px 字体大小?
- jquery - 列出、计数元素,但属性不可用