写了一个这样的布局:
<LinearLayout 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"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:src="@drawable/apk_analyse_tem" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
Eclipse提示:This tag and its children can be replaced by one <TextView/> and a compound drawable。原因是可以在Java代码里直接通过setCompoundDrawables()等方法,或者在布局文件里通过android:drawableTop=""等属性给TextView添加图片。
Java代码:
TextView text = (TextView) findViewById(R.id.text1);
text.setCompoundDrawables(null, this.getResources().getDrawable(R.drawable.apk_analyse_tem), null, null);
xml布局:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:drawableTop="@drawable/apk_analyse_tem"
android:drawablePadding="5dp"
android:text="@string/hello_world" />