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);
}
}