2014-10-29 48 views
0

我有一個佈局,其中一個內部不在中心,它只發生在少數分辨率的設備上,而在少數情況下它完全處於中心。下面是代碼和截圖如何以分辨率在中心顯示圖像

<ImageView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" android:gravity="center" 
       android:src="@drawable/thank" android:paddingTop="10dip" 
       android:paddingBottom="10dip"/> 

代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/splash_layout" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:gravity="center" android:orientation="vertical" 
    android:background="@drawable/background"> 

    <ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:gravity="center_horizontal" 
     android:src="@drawable/logo" android:paddingTop="10dip" 
     android:paddingBottom="10dip" /> 

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <ImageView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:gravity="center" 
      android:src="@drawable/thank" android:paddingTop="10dip" 
      android:paddingBottom="10dip"/> 

     <com.teleca.sam.ui.Copyright 
      android:layout_width="fill_parent" android:layout_height="fill_parent" 
      android:gravity="bottom|center"/> 
    </RelativeLayout> 
</LinearLayout> 
+0

你可以使用一個RelativeLayout – Raghunandan 2014-10-29 08:10:01

回答

2

如果您使用的是LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:layout_gravity="center_horizontal" 
     android:src="@drawable/ic_launcher" /> 
</LinearLayout> 

如果您使用的是RelativeLayout

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

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:src="@drawable/ic_launcher" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 
1

,因爲你的ImageView是一個RelativeLayout的,你應該使用

android:layout_centerInParent="true" 

,而不是

android:gravity="center" 

您ImageView標籤

0

RelativeLayout的可能是這樣做的原因。改爲嘗試線性佈局。