-1

I am trying to customize the layout of a dialog. I want to have a logo in the top left corner and in the right of it, the title of the dialog. I wrote the layout below, but the editor in eclipse gives me the layout shown below, and I do not know why the logo is so wide? and the title should be to the right of it. please let me know what I am doing wrong?

layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TableLayout
    android:id="@+id/tl_MainTable"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <TableRow 
        android:id="@+id/tr_Logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:id="@+id/iv_Logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher"/>
    </TableRow>
    <TableRow 
        android:id="@+id/tr_Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">
        <TextView 
            android:id="@+id/tv_Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Discovering Neigbouring Devices"
            android:/>
    </TableRow>

</TableLayout>

enter image description here

Víctor Martín
  • 3,352
  • 7
  • 48
  • 94
rmaik
  • 1,076
  • 3
  • 15
  • 48

3 Answers3

2

First of all use android:src instead android:background

So finally your ImageView

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@android:drawable/sym_def_app_icon"
    android:layout_weight="1"
    android:adjustViewBounds="true"/>

FYI : Use Linear Layout Instead Table Layout .

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

You have so wide logo, because you use TableRow.

Try to add android:layout_weight="1" for ImageView.

Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
1

You need to use RelativeLayout or LinearLayouts. TableLayout is not good for this.

This is an example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="@color/material_deep_teal_500">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@android:drawable/sym_def_app_icon"
        android:layout_weight="1" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="LOGONAME"
        android:id="@+id/textView"
        android:layout_weight="8"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/abc_action_bar_overflow_padding_end_material" />
</LinearLayout>

enter image description here

Víctor Martín
  • 3,352
  • 7
  • 48
  • 94
  • thanks for ur answer. i tried android:gravity="center_vertical" in my tablelayout to see whther it will work fine or not, but the text still in its position an does not move to be in the CenterVertica o fthe TableRow layout...any idea why that is hapenning?? thenk you – rmaik Aug 27 '15 at 10:44
  • TableLayout is your problem, you can copy only the part of my code inside the "LinearLayout" incluing it. TableLayout has other purposes. – Víctor Martín Aug 27 '15 at 10:47
  • i tried your answer but i receive a warning says: the linearlyout or the relative layout are useless – rmaik Aug 27 '15 at 11:53
  • That warning is saying you that you have a LinearLayout inside another LinearLayout, with nothing more, so If you want you can delete one. It is not an error, it's an alert. – Víctor Martín Aug 27 '15 at 21:34