android中插入图片的三种方式

时间:2025-02-08 08:40:06

1.

<RelativeLayout xmlns:android="/apk/res/android"
    xmlns:tools="/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
  >



    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
    <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/timg"/>
</RelativeLayout>

2.

<RelativeLayout xmlns:android="/apk/res/android"
    xmlns:tools="/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/timg" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

3.

package ;

import ;
import ;
import ;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(.activity_main);
        getWindow().setBackgroundDrawableResource();
    }   
}

3中方法各有优缺点,自己尝试一下,顺便说一下,高清图片不支持的哦