2013-07-31 51 views
0

Actual View不能對齊ImageViews到左側ListView中的行(RelativeLayout的)

這是我有我此刻的視圖。

正如你所看到的,圖標並不是全部對齊到左邊。紅線是我的目標。如果他們一直走到左邊,沒問題,因爲我可以用marginLeft以後解決。

這是我的XML代碼(佈局/ listview_style_listview.xml):

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/BackGroundColor" 
    android:orientation="vertical" 
    android:scaleType="center" > 

    <LinearLayout 
     android:id="@+id/titleLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="2dp" 
     android:layout_marginBottom="2dp" 
     android:layout_marginLeft="7dp" 
     android:layout_marginRight="7dp" 
     android:background="@color/BackGroundColor" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/sectionTitle" 
      style="@style/sectionTitle" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:gravity="left" 
      android:text="(blank)" /> 

     <Button 
      android:id="@+id/sectionInfoButton" 
      android:layout_width="33dp" 
      android:layout_height="33dp" 
      android:layout_gravity="right" 
      android:layout_marginLeft="3dp" 
      android:layout_weight="0" 
      android:background="@drawable/infoicon" /> 

     <Button 
      android:id="@+id/sectionInfoButton" 
      android:layout_width="33dp" 
      android:layout_height="33dp" 
      android:layout_gravity="right" 
      android:layout_marginLeft="3dp" 
      android:layout_weight="0" 
      android:background="@drawable/filtericon" /> 

     <Button 
      android:id="@+id/sectionOptionsButton" 
      android:layout_width="33dp" 
      android:layout_height="33dp" 
      android:layout_gravity="right" 
      android:layout_marginLeft="3dp" 
      android:layout_weight="0" 
      android:background="@drawable/menuicontop2" /> 

     <Button 
      android:id="@+id/addCatButton" 
      android:layout_width="33dp" 
      android:layout_height="33dp" 
      android:layout_gravity="right" 
      android:layout_marginLeft="3dp" 
      android:layout_weight="0" 
      android:background="@drawable/effect_button_add_cat_click" /> 
    </LinearLayout> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="3dp" 
     android:layout_marginBottom="0dp" 
     android:layout_marginLeft="0dip" 
     android:layout_marginRight="0dip" 
     android:background="@color/blueOceanStroke" /> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:divider="@color/BlueOcean" 
     android:dividerHeight="1dp" 
     android:listSelector="@drawable/listview_style_list_selector" 
     android:paddingBottom="1dp" /> 

</LinearLayout> 

這是我的XML代碼(佈局/ listview_style_row.xml

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

    <ImageView 
     android:id="@+id/catThumbnail" 
     android:layout_width="32dp" 
     android:layout_height="32dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/bank1" /> 

    <TextView 
     android:id="@+id/sectionTitle" 
     style="@style/title" 
     android:layout_width="97dp" 
     android:layout_height="32dp" 
     android:layout_alignBottom="@+id/catThumbnail" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginLeft="66dp" 
     android:gravity="center_vertical" 
     android:text="Title Text" 
     android:textColor="@color/listsTextColor" 
     android:textSize="15sp" 
     android:textStyle="normal" 
     android:typeface="normal" /> 

    <ImageView 
     android:layout_width="25dip" 
     android:layout_height="32dp" 
     android:layout_alignBottom="@+id/sectionTitle" 
     android:layout_alignParentRight="true" 
     android:gravity="center_vertical" 
     android:src="@drawable/arrow" /> 

</RelativeLayout> 

PS:我截圖後在右側添加了一個箭頭圖標,這就是爲什麼它不顯示在圖像上,但我想這不重要。

+0

剛剛發佈的代碼究竟是什麼?我猜是你的listview中的每個項目?你還可以發佈包含你的列表視圖的佈局嗎? – mpellegr

+0

hello mpellegr。是的,我發佈的是「行風格」。我已更新了「listview_style_row」所在的佈局。如果您需要其他任何內容,請詢問。 –

+0

您是否嘗試將設置填充爲0並將背景設置爲null,以便使用id爲'catThumbnail'的imageview?有時候視圖可以有默認的填充值。 – ecem

回答

0

從屏幕截圖中可以看出,佈局還是可以的,因爲帶有背景顏色@ color/blueOceanStroke的分隔線可以一路走來,分隔線也是如此。如果您測量紅線與黃色方塊左邊緣之間的距離,並將其與方塊右邊緣與字母左邊緣之間的距離進行比較,則問題必須出現在「@ + id/catThumbnail」中「B」他們差不多是一樣的。

我的猜測是在@ drawable/bank1中有一些填充的國王。嘗試徹底刪除它,看看字母「B」是否與標題保持一致。

希望這有助於...

+0

嗨克里斯托。我檢查了。 @ drawable/bank1是一個48px的方形.png。那不是問題 –

0

我能夠與Android修復:layout_marginLeft = 「 - 10dp」 在listview_style_row.xml的 「ImageView的@ + ID/catThumbnail」,但我真的不認爲這是最終完美設計的應用程序的有效解決方案,是嗎?對於我來說,負面的價值在那裏,有錯誤的東西,對吧?

+0

這可能適用於某些設備,但這不是一個很好的一般方法。如果您對圖片視圖左側有意見,則可能會導致他們移動。見http://stackoverflow.com/questions/10673503/is-it-a-bad-practice-to-use-negative-margins-in-android。 – mpellegr

0

正如其他人提到的,我會嘗試刪除ImageView並查看TextView是否與紅線齊平。如果是這樣,ImageView有一些問題,如果不是這是別的。此外,ImageView可能不具有相同的高度和寬度,並且可能會因設置爲32 dp而導致縮放比例出現問題,請參閱:Unwanted padding around an ImageView

將ImageView封裝在FrameLayout中可能更容易。事情是這樣的:

<FrameLayout> 
    android:layout_width="32dp" 
    android:layout_height="32dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" > 

    <ImageView 
     android:id="@+id/catThumbnail" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/bank1" /> 

</FrameLayout> 

或者,如果還是不行,請嘗試將圖像視圖和/或框架佈局WRAP_CONTENT的寬度和高度。此外,如果該圖像是9補丁,可能還有其他原因。