0

I am creating custom ActionBar with two images and text. The first ImageView (icon) shall be fixed to the left, next to it the TextView, second ImageView (image) to be fixed to the right. The size of images and text must be the same on all screens. How can I do this?

<?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>
Andrew Efremov
  • 423
  • 5
  • 12
  • use this example to use a tool bar as the action bar, you can modify the toolbar as a normal layout: http://stackoverflow.com/questions/26443403/toolbar-and-contextual-actionbar-with-appcompat-v7 – xanexpt Jun 16 '15 at 12:13
  • you can use Relativelayout ... and set the gravity to left and right on your views.. its simple.. or use the toolbar.. its Material design way .. and best way.. you can implement here visit this.. http://stackoverflow.com/a/30400594/3498931 – Ajay P. Prajapati Jun 16 '15 at 14:39
  • thanks to all, i solved this problem – Andrew Efremov Jun 16 '15 at 14:56

0 Answers0