2014-02-20 48 views
0

嗨我正在使用ActionBar的自定義視圖。在我有followiong問題...請任何一個可以幫助我如何對齊自定義視圖項

enter image description here

AS我旋轉屏幕的所有項目移動到左側,但我希望他們對齊我使用線性equal.For自定義視圖佈局..

以下是我的自定義視圖代碼..

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

<ImageView 
    android:id="@+id/imageViewmail" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_msg" 
    android:gravity="center" 
    android:layout_marginLeft="40sp" 
    android:contentDescription="@string/app_name"/> 

<ImageView 
    android:id="@+id/imageViewnotification" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_notification1" 
    android:layout_marginLeft="40sp" 
    android:contentDescription="@string/app_name"/> 

<ImageView 
    android:id="@+id/imageViewsettings" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_settings" 
    android:layout_marginLeft="40sp" 
    android:contentDescription="@string/app_name"/> 

<ImageView 
    android:id="@+id/imageViewsearch" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_search" 
    android:layout_marginLeft="40sp" 
    android:contentDescription="@string/app_name"/> 

回答

0

使用android:weightSum="4"LinearLayoutandroid:layout_weight="1"每個ImageView。這樣

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
... 
android:weightSum="4" 
android:gravity="center"> 

<ImageView 
    ... 
    android:layout_weight="1" /> 

<ImageView 
    ... 
    android:layout_weight="1" /> 

<ImageView 
    ... 
    android:layout_weight="1" /> 

<ImageView 
    ... 
    android:layout_weight="1" /> 

[編輯]還需要設置layout_width="0dp"每個ImageView
希望它幫助歡呼:)

+0

我試過你的代碼,但仍然沒有發生..並記住我設置它在ActionBar – Akshay

0

SMR接近。 LinearLayout必須具有orientation =「horizo​​ntal」,並且每個ImageView必須具有權重(您已經完成此操作)以及layout_width =「match_parent」。

相關問題