android 中将图片放在银屏中心的方法,不改变图片的大小
android 中将图片放在屏幕中心的方法,不改变图片的大小
目前只知道2种方法,第一种是通过 设置 和屏幕的边距 第二种 是设立 把ImageView套在LinearLayout 里边然后再设置LinearLayout的位置 我会把起决定性作用的属性用红色标出来不多废话了 大家看看就知道了。
方法一
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/spaceshipImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="151px"
android:layout_marginBottom="151px"
android:layout_marginLeft="96px"
android:layout_marginRight="96px"
android:src="@drawable/linuxconf"/>
</LinearLayout>
方法二
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/spaceshipImage"
android:layout_width="wrap_content"
android:src="@drawable/happy"
android:layout_height="wrap_content" />
</LinearLayout>
目前只知道2种方法,第一种是通过 设置 和屏幕的边距 第二种 是设立 把ImageView套在LinearLayout 里边然后再设置LinearLayout的位置 我会把起决定性作用的属性用红色标出来不多废话了 大家看看就知道了。
方法一
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/spaceshipImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="151px"
android:layout_marginBottom="151px"
android:layout_marginLeft="96px"
android:layout_marginRight="96px"
android:src="@drawable/linuxconf"/>
</LinearLayout>
方法二
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/spaceshipImage"
android:layout_width="wrap_content"
android:src="@drawable/happy"
android:layout_height="wrap_content" />
</LinearLayout>