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>
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 .
You have so wide logo, because you use TableRow
.
Try to add android:layout_weight="1"
for ImageView.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.