Issue
I have a dynamic judgment, so i set drawable left by java.
My problem is, I don't know hot to adjust my image position, I have try to use
android:drawablePadding=""
in xml and setCompoundDrawablePadding();
in java.
Both of them change my text position not image.
I still try to change drawable.setBounds()
setting, but it looks like change the proportion not position.
How do i change my image inside the button ? Any help would be appreciated. Thanks in advance.
Here is my bttuon.xml:
<Button
android:id="@+id/goToPersonalPage"
android:layout_width="145dp"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:background="@drawable/button_oval"
android:text="@string/memberButton"
android:textColor="#29395e"
android:textSize="18dp" />
and here is my code about button:
goToPersonalPage.setCompoundDrawables(setIcon(R.drawable.btn_member_green_128x128), null, null, null);
setIcon function is:
private Drawable setIcon(int id) {
Drawable drawable = getResources().getDrawable(id);
drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * 0.2),
(int) (drawable.getIntrinsicHeight() * 0.2));
return drawable;
}
Solution
Add android:paddingLeft="20dp"
to add left padding for you Button
<Button
android:id="@+id/goToPersonalPage"
android:layout_width="145dp"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:background="@drawable/button_oval"
android:text="@string/memberButton"
android:textColor="#29395e"
android:paddingLeft="20dp"
android:textSize="18dp" />
Use android:gravity="right"
to change the position of TextView
.
Answered By - KeLiuyue
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.