<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.jay.example.test.MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:drawableTop="@drawable/user_48" android:drawablePadding="4dp" android:gravity="center" android:text="用户" /> </RelativeLayout>
txt = (TextView) findViewById(R.id.txt); Drawable[] drawable = txt.getCompoundDrawables(); // 数组下表0~3,依次是:左上右下 drawable[0].setBounds(100, 0, 200, 200); txt.setCompoundDrawables(drawable[0], drawable[1], drawable[2], drawable[3]);