控件 - ImageView

ImageView 图片

图片

属性

  • android:id:ID,唯一标识符。
  • android:layout_width:宽。
    match_parent:当前控件大小和父控件一样。
    wrap_content:当前控件大小刚好包含里边内容。
  • android:layout_height:高,同上。
  • android:src:图片路径

示例代码

activity_com_image_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".chapter03.ImageViewActivity"
    android:orientation="vertical">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/iv_imageview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher_background" />

        </LinearLayout>
    </ScrollView>

</LinearLayout>

ImageViewActivity.java

public class ImageViewActivity extends MyBaseActivity {

    ImageView iv_imageview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_com_image_view);

        iv_imageview = findViewById(R.id.iv_imageview);
        iv_imageview.setImageResource(R.drawable.img_1);
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。