如何更改 java 中 xml 的 ImageButton 大小
How can I change ImageButton size from xml in java
我的 android 项目有一些问题。
这是我的 xml 固定宽度和高度的 ImageButton 代码。
<ImageButton
android:layout_width="120dp"
android:layout_height="120dp"
android:id="@+id/ball1"
android:background="@drawable/ball"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
我在 java 中调用 ImageButton:
ImageButton ball1 = (ImageButton) findViewById(R.id.ball1);
我的问题是,我需要做什么,减去我的layout_width 和 layout_height
在 java 代码中增加 10dp?
像这样:
int width = ball1.getWidth();
int height = ball1.getHeight();
width = width - 10dp;
height = height - 10dp;
那么如何将高度和宽度减去 10dp?
您可以通过
imagebutton.setLayoutParams(new LinearLayout.LayoutParams(50, 50));
或使用以下link
http://android-coding.blogspot.in/2011/05/resize-button-programmatically-using.html
我的 android 项目有一些问题。
这是我的 xml 固定宽度和高度的 ImageButton 代码。
<ImageButton
android:layout_width="120dp"
android:layout_height="120dp"
android:id="@+id/ball1"
android:background="@drawable/ball"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
我在 java 中调用 ImageButton:
ImageButton ball1 = (ImageButton) findViewById(R.id.ball1);
我的问题是,我需要做什么,减去我的layout_width 和 layout_height 在 java 代码中增加 10dp?
像这样:
int width = ball1.getWidth();
int height = ball1.getHeight();
width = width - 10dp;
height = height - 10dp;
那么如何将高度和宽度减去 10dp?
您可以通过
imagebutton.setLayoutParams(new LinearLayout.LayoutParams(50, 50));
或使用以下link
http://android-coding.blogspot.in/2011/05/resize-button-programmatically-using.html