`
byandby
  • 浏览: 1688544 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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>
分享到:
评论
1 楼 wavechao 2012-07-19  
第一种方法里面的
android:layout_marginTop="151px"
  android:layout_marginBottom="151px"
  android:layout_marginLeft="96px"
  android:layout_marginRight="96px"
对各种分辨率的都有效吗

相关推荐

Global site tag (gtag.js) - Google Analytics