2015-07-20 97 views
1

我不確定這是怎麼發生的 - 但是我有一個imageView,我試圖在屏幕的左側實現 - 但是它當我嘗試運行佈局時,它居中,我不確定原因。ImageView不會左對齊在RelativeLayout中使用android:layout_alignParentLeft =「true」

任何建議,非常感謝。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ListView_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="1" > 

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

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:gravity="left" /> 

     <ProgressBar 
      android:id="@+id/progressbar_Horizontal" 
      style="?android:attr/progressBarStyleHorizontal" 
      android:layout_width="340dp" 
      android:layout_height="15dp" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:max="100" 
      android:progressDrawable="@drawable/progressbar2" /> 

     <ImageView 
      android:id="@+id/downloadbtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/progressbar_Horizontal" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="10dp" 
      android:src="@drawable/button_download" /> 

     <RelativeLayout 
      android:id="@+id/footer" 
      style="@android:style/ButtonBar" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:orientation="horizontal" > 

      <Button 
       android:id="@+id/saveButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </RelativeLayout> 
    </RelativeLayout> 

</LinearLayout> 
+0

你可以發佈截圖嗎?我想我知道問題是什麼,但需要更清晰! –

+0

http://i.stack.imgur.com/mKlGj.jpg – AndroidAndroidAndroid

+0

你想把海報對準左邊? –

回答

0

更改您imageView1如下佈局:

<ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:adjustViewBounds="true" 
     android:layout_height="fill_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:gravity="left" /> 

你已經設置的ImageView的寬度,以填補父,這是造成問題的原因。此片段填充高度,然後根據圖片的尺寸調整寬度。

+0

奇怪......它現在沒有出現。 http://pastebin.com/MFaeaEDU – AndroidAndroidAndroid

+0

我不確定你需要:android:adjustViewBounds =「true」 – bkurzius

0

您的圖像寬度和高度設置爲「fill_parent」 - 嘗試將它們都設置爲「wrap_content」。

+0

我嘗試了你建議的方法......現在我看不到imageView1。 http://pastebin.com/dNkaPdF5 – AndroidAndroidAndroid

+0

實際上改變高度和寬度以使用wrap_content,如果仍然不起作用,請嘗試將臨時圖像硬編碼到xml中,以驗證問題是否與您的方式不符在運行時設置圖像 – bkurzius

0

試試這個嗎?

<ImageView 
     android:id="@+id/downloadbtn" 
     android:layout_width="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/progressbar_Horizontal" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="10dp" 
     android:src="@drawable/button_download"/> 

這對我的作品:)

+0

http://pastebin.com/J3thJ1rk http://postimg.org/image/6kgww2swx/ 我嘗試了你的建議......它仍然出現在屏幕中間 – AndroidAndroidAndroid

0

我正面臨着類似的問題時,我並沒有對ImageView的設置任何固定尺寸。嘗試給ImageView固定的高度和寬度。對我來說有詭計了。