2014-05-15 25 views
0

我已經閱讀了幾篇關於如何執行此操作的教程,但無論出於何種原因,我的圖片都不會從屏幕中心移出。忍者形象是1080x517px無法將ImageView對齊到RelativeLayout的底部

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:weightSum="1" 
       android:background="@color/white"> 

    <ImageView 
     android:id="@+id/ninjas" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/ninjas" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentBottom="true"/> 

</RelativeLayout> 

從我可以告訴,這是正確的。有什麼建議麼? 在此先感謝

回答

0

嘗試改變

<ImageView 
    android:id="@+id/ninjas" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/ninjas" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true"/> 

<ImageView 
    android:id="@+id/ninjas" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ninjas" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true"/> 

目前您的ImageView佔據所有空間在其父。改變layout_widthlayout_heightwrap_content後只會佔據儘可能多的空間的@drawable/ninjas

+0

感謝。我嘗試過,但它似乎沒有改變。默認圖像大小爲1080x517px,但是我正在N5上測試。我不確定圖像尺寸是否會干擾佈局,就像我使用應用程序圖標一樣,它位於正確的位置。 – K20GH

+0

然後它的圖像大小問題 – Apoorv

+0

N5是1080px寬,圖像也是如此。當然,重點在於圖像可以縮放到ImageView的寬度並保持比例,因此它與圖像的大小無關... – K20GH

1

大小您使圖像填充父當前。變化

android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
1

試試這個

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#ffffff" > 

<ImageView 
    android:id="@+id/ninjas" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 
0
// Try this way,hope this will help you to solve your problem... 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:gravity="bottom|right" 
    android:padding="5dp"> 

    <ImageView 
     android:id="@+id/ninjas" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ninjas" 
     android:adjustViewBounds="true"/> 

</LinearLayout