2013-05-30 1 views
1

Мне нужно добавить 3 изображения в мою панель заголовка пользовательского окна. gravity 1-го изображения left. gravity второго изображения center и gravity третьего изображения right. Я использовал приведенный ниже код. но третье изображение не отображается. Я думаю, что он покрыт вторым изображением.Добавить изображения в пользовательскую панель заголовка окна в Android

Как я могу отобразить 3 изображения в вышеуказанных позициях?

<?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="35dip" 
    android:background="#323331" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" 
    android:paddingLeft="5dip" > 

    <ImageView 
     android:id="@+id/header_left" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/header_img_dec" 
     android:src="@drawable/left_logo" /> 

    <ImageView 
     android:id="@+id/header_middle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/header_img_dec" 
     android:gravity="center" /> 

    <ImageView 
     android:id="@+id/header_right" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:contentDescription="@string/header_img_dec" 
     android:src="@drawable/right_img" /> 

</LinearLayout> 

ответ

2

Использование макета весов для этого, а также установить android:layout_gravity="center_horizontal" для родителей LinearLayout

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="35dip" 
    android:background="#323331" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" 
    android:layout_gravity="center_horizontal" 
    android:paddingLeft="5dip" > 

     <ImageView 
      android:id="@+id/header_left" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/header_img_dec" 
      android:src="@drawable/left_logo" 
      android:layout_weight="1" 
       /> 

     <ImageView 
      android:id="@+id/header_middle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:contentDescription="@string/header_img_dec" 
      android:layout_weight="1" /> 

     <ImageView 
      android:id="@+id/header_right" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:contentDescription="@string/header_img_dec" 
      android:src="@drawable/right_img" /> 

    </LinearLayout> 
0

попробовать этот способ

<code>enter image description here</code>

<?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="35dip" 
    android:background="#323331" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" 
    android:paddingLeft="5dip" > 

<ImageView 
    android:id="@+id/header_left" 
    android:layout_alignParentLeft="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:contentDescription="@string/header_img_dec" 
    android:src="@drawable/left_logo" /> 

<ImageView 
    android:id="@+id/header_right" 
    android:layout_width="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_height="wrap_content" 
    android:contentDescription="@string/header_img_dec" /> 

<ImageView 
    android:id="@+id/header_middle" 
    android:layout_width="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_height="wrap_content" 
    android:contentDescription="@string/header_img_dec" 
    android:src="@drawable/right_img" /> 
</RelativeLayout> 
0

Во втором ImageView он пропустил андроида: SRC = и вы использовали android: layout_width = "fill _parent». поэтому используйте вместо android: layout_width = "wrap_content", иначе изображение заполнит все пространство контейнера. Чтобы расположить изображения друг с другом, я советую вам использовать RelativeLayout

Попробуйте это:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#323331" 
    > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="82dp" 
     android:layout_toRightOf="@+id/imageView1" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/imageView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 
5

Изменение android:layout_width="fill_parent" к android:layout_width="wrap_content"