2015-06-16 4 views
0

Я создаю пользовательские ActionBar и у меня есть RelativeLayut с двумя изображениями и текстом. Я хочу, чтобы второй ImageView был зафиксирован справа, но я не могу этого сделать. Он сдвигается в зависимости от разрешения экрана. Как я могу решить эту проблему?Как исправить изображение справа?

<?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="fill_parent" > 
<ImageView 
    android:id="@+id/icon" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:contentDescription="@null" 
    android:layout_marginTop="8dp" 
    android:layout_marginBottom="8dp" 
    android:layout_marginLeft="8dp" 
    android:src="@drawable/ic_launcher" /> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_marginTop="13dp" 
    android:id="@+id/layout_text" 
    android:layout_toRightOf="@id/icon" 
    android:orientation="vertical" 
    > 
    <TextView 
     android:id="@+id/actionbar_title" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="mAPP" 
     android:textSize="@dimen/actionbar_title_text_size" 
     android:textColor="#ffffff" /> 
</LinearLayout> 

<ImageView 
    android:id="@+id/image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:contentDescription="@null" 
    android:layout_toRightOf="@id/layout_text" 
    android:layout_marginTop="8dp" 
    android:layout_marginBottom="8dp" 
    android:layout_alignParentRight="true" 
    android:src="@drawable/ic_image" /> 
    </RelativeLayout> 
+0

Какой 'ImageView'? Один с id 'image' или' icon'? Также, пожалуйста, пройдите через некоторый учебник о 'RelativeLayout'. Кажется, у вас есть путаница. – Sufian

+0

С id 'image'. –

ответ

2

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

<?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="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="6"> 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginTop="8dp" 
     android:contentDescription="@null" 
     android:src="@drawable/ic_launcher" 
     android:layout_weight="1"/> 

    <LinearLayout 
     android:id="@+id/layout_text" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="4" 
     android:layout_marginBottom="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginTop="8dp" 
     android:layout_toRightOf="@id/icon" 
     android:layout_gravity="center_vertical"> 

     <TextView 
      android:id="@+id/actionbar_title" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="mAPP" 
      android:gravity="center_vertical" 
      android:textColor="#ffffff" 
      android:textSize="@dimen/actionbar_title_text_size" /> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="8dp" 
     android:layout_marginTop="8dp" 
     android:layout_weight="1" 
     android:layout_toRightOf="@id/layout_text" 
     android:contentDescription="@null" 
     android:src="@drawable/ic_image" /> 
</LinearLayout> 

Что изменилось является родительским макет LinearLayout затем дал веса своим детям, что это все.

+0

Пожалуйста, также объясните, что вы сделали, так что это не ложка для OP. – Sufian

+0

Как сохранить одинаковый размер? –

+0

Что вы подразумеваете под одинаковым размером? вы имеете в виду высоту вашего родительского макета? или его детей? – blueware

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