Android UI教程 - Android ImageView

2018-01-09 14:51 更新

Android UI教程 - Android ImageView


下面的代碼顯示了ImageViews的一些XML示例,后面跟著一些代碼展示了如何創(chuàng)建一個 ImageView 。

例子

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/image3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

以下Java代碼設(shè)置來自資源的映像。

package com.java2s.app;
//  www  . j a v  a  2 s.c o  m
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageView imgView = (ImageView) findViewById(R.id.image3);

        imgView.setImageResource(R.drawable.ic_launcher);
    }

}
null


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號