2014-02-20 4 views
0

Привет Я использую пользовательский вид для ActionBar. В том, что у меня есть followiong проблемы ... пожалуйста, может ли один помочь мнеКак выровнять пользовательские элементы вида

enter image description here

AS поворачивать экран все элементы двигаться к левой стороне, но я хочу, чтобы они выровнять equal.For настраиваемое представление я использую Linear Компоновка ..

Ниже мой код для пользовательского вида ..

<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" для LinearLayout и android: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" /> 

[EDIT] также необходимо установить layout_width="0dp" для каждого ImageView
Надеюсь, что это помогает ура :)

+0

Я пробовал свой код, но все еще не происходит .. и помню, что я устанавливаю его на ActionBar – Akshay

0

SMR близко. LinearLayout должен иметь ориентацию = «горизонтальный», и каждый ImageView должен иметь вес (вы уже это сделали), а также layout_width = «match_parent».

Смежные вопросы