friends,
here is my layout with image and text.
i want to show text vertical align to imageview any one guide me what should i do?
right now it is top align.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/bankIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:scaleType="centerInside"
/>
<TextView
android:id="#+id/bankName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/bankIcon"
android:layout_alignWithParentIfMissing="true"
android:scrollHorizontally="false"
android:textColor="#color/Bank_list_item_color"
android:layout_marginRight="30dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Please used below line in TextView..
android:layout_centerVertical="true"
Two possibilities:
Add android:layout_centerVertical="true"
Change android:layout_height from wrap_content to fill_parent and add android:gravity="center_vertical"
Try this code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/bankIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:scaleType="centerInside"
/>
<TextView
android:id="#+id/bankName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/bankIcon"
android:layout_alignWithParentIfMissing="true"
android:scrollHorizontally="false"
android:textColor="#color/Bank_list_item_color"
android:layout_marginRight="30dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Textview property android:layout_centerInParent="true" worked for me.
Related
I want to create my Toolbar layout like below image.
I written below code for create this view. Please see my xml Code.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/_40sdp"
android:background="#color/black"
android:padding="#dimen/_5sdp">
<ImageView
android:id="#+id/toolbar_default_img_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:padding="#dimen/_5sdp"
android:src="#drawable/icon_menu" />
<TextView
android:id="#+id/toolbar_default_textview_title"
style="#style/textview_normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/toolbar_default_img_menu"
android:layout_toStartOf="#+id/toolbar_default_img_search"
android:text="#string/app_name"
android:textColor="#color/white"
android:textSize="#dimen/_15ssp" />
<ImageView
android:id="#+id/toolbar_default_img_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="#+id/toolbar_default_img_filter_tag"
android:padding="#dimen/_5sdp"
android:src="#drawable/icon_search" />
<ImageView
android:id="#+id/toolbar_default_img_filter_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="#+id/toolbar_default_img_filter"
android:padding="#dimen/_5sdp"
android:src="#drawable/icon_filter" />
<ImageView
android:id="#+id/toolbar_default_img_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:padding="#dimen/_5sdp"
android:src="#drawable/icon_filter" />
</RelativeLayout>
After written this code i can see my view is correct in android studio preview but when i run my project it look like below image.
only left and right imageview on correct position but my textview and other two imageview is not set on correct position after run this code.
May be problem with android:layout_toEndOf and android:layout_toStartOf property of RelativeLayout.
I don't know why this problem create.Thank you for help.
Replace this code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/_40sdp"
android:background="#color/black"
android:padding="#dimen/_5sdp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:layout_centerVertical="true"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/toolbar_default_img_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/_5sdp"
android:src="#drawable/ic_launcher_background" />
<TextView
android:id="#+id/toolbar_default_textview_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:maxEms="50"
android:text="#string/app_name" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/toolbar_default_img_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="#dimen/_5sdp"
android:src="#drawable/icon_search" />
<ImageView
android:id="#+id/toolbar_default_img_filter_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="#dimen/_5sdp"
android:src="#drawable/icon_filter" />
<ImageView
android:id="#+id/toolbar_default_img_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/_5sdp"
android:src="#drawable/icon_filter" />
</LinearLayout>
</RelativeLayout>
Do changes as per your requirement by padding and margin to make a proper design.
Try using layout_alignParentRight , layout_toLeftOf , layout_toRightOf ,layout_alignParentLeft instead of layout_alignParentEnd , layout_toStartOf , layout_toEndOf and layout_alignParentStart or use Both in the 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#color/black"
android:padding="5dp">
<ImageView
android:id="#+id/toolbar_default_img_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:src="#drawable/add_btn" />
<TextView
android:id="#+id/toolbar_default_textview_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/toolbar_default_img_menu"
android:layout_toLeftOf="#+id/toolbar_default_img_search"
android:text="#string/app_name"
android:textColor="#color/white"
android:textSize="15sp" />
<ImageView
android:id="#+id/toolbar_default_img_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/toolbar_default_img_filter_tag"
android:padding="5dp"
android:src="#drawable/add_btn" />
<ImageView
android:id="#+id/toolbar_default_img_filter_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/toolbar_default_img_filter"
android:padding="5dp"
android:src="#drawable/add_btn" />
<ImageView
android:id="#+id/toolbar_default_img_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:src="#drawable/add_btn" />
</RelativeLayout>
</RelativeLayout>
you need to add them as action button on the appbar
https://developer.android.com/training/appbar/actions.html
You need to add
android:layout_toLeftOf
along with
android:layout_toStartOf
and
android:layout_toRightOf
with
android:layout_toEndOf
Add
android:layout_toLeftOf:
along with
android:layout_toStartOf:
and
android:layout_toRightOf:
with
android:layout_toEndOf:
because you need to support lower API versions.
Fairly new to Android dev, I'm having trouble with a RelativeLayout. In the following XML example, I would expect my ImageButton (on the right, with the '+') to match the RelativeLayout height. However, it doesn't, as shown on this image:
Why isn't the right button with the '+' matching the maximum possible height ?
Here's the related code:
<?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="wrap_content"
android:background="#drawable/artist_cell_background">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:src="#drawable/ic_music_note_24dp">
</ImageView>
<ImageButton
android:id="#+id/artist_button"
android:src="#drawable/ic_add_24dp"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/artist_cell_playlist_button_background">
</ImageButton>
<TextView
android:id="#+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button">
</TextView>
<TextView
android:id="#+id/number_of_albums"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button"
android:layout_below="#id/artist_name">
</TextView>
</RelativeLayout>
Thanks for any help or idea.
EDIT: What I want is the right button to occupy the height of the line, i.e. have the same height than the two text zones of the middle plus top and bottom margins, no more no less.
As I can understand from the XML, it seems you want to make the "+" button more clickable.
I would suggest you to have some padding and that should do the job.
EDIT 1 : You may do the following without padding, by aligning Top and Bottom of the ImageView to the relevant TextView
<?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="wrap_content"
android:background="#drawable/artist_cell_background">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:src="#drawable/ic_music_note_24dp">
</ImageView>
<TextView
android:id="#+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:paddingTop="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button">
</TextView>
<TextView
android:id="#+id/number_of_albums"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:paddingBottom="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button"
android:layout_below="#id/artist_name">
</TextView>
<ImageButton
android:id="#+id/artist_button"
android:src="#drawable/ic_add_24dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignTop="#id/artist_name"
android:layout_alignBottom="#id/number_of_albums"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/artist_cell_playlist_button_background">
</ImageButton>
</RelativeLayout>
Put your relative layout inside a linear layout that should do it
<?xml version="1.0" encoding="utf-8"?>
<LinearLaout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/artist_cell_background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:src="#drawable/ic_music_note_24dp">
</ImageView>
<ImageButton
android:id="#+id/artist_button"
android:src="#drawable/ic_add_24dp"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/artist_cell_playlist_button_background">
</ImageButton>
<TextView
android:id="#+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button">
</TextView>
<TextView
android:id="#+id/number_of_albums"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#id/imageView"
android:layout_toEndOf="#id/imageView"
android:layout_toLeftOf="#id/artist_button"
android:layout_toStartOf="#id/artist_button"
android:layout_below="#id/artist_name">
</TextView>
</RelativeLayout>
</LinearLayout>
Your image may be small. Use android:scaleType="fitCenter" in the ImageButton.
Also try removing default padding and margin from the ImageButton by setting them to 0dp.
With the help of #rex, I figured out how to do this: enclose the left picture and the 2 TextViews in a RelativeLayout (this sets the size of the main RelativeLayout), and align top and bottom the ImageButton to this layout.
The code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/artist_cell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/cell_background">
<ImageButton
android:id="#+id/artist_plus_button"
android:src="#drawable/ic_add_24dp"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignTop="#+id/artist_infos"
android:layout_alignBottom="#+id/artist_infos"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/plus_button_background"
android:contentDescription="#string/artistPlusButtonCD">
</ImageButton>
<RelativeLayout
android:id="#id/artist_infos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/artist_plus_button"
android:layout_toStartOf="#id/artist_plus_button">
<ImageView
android:id="#+id/album_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_music_note_24dp"
android:contentDescription="#string/albumCoverContentDescription">
</ImageView>
<TextView
android:id="#+id/artist_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/album_cover"
android:layout_toEndOf="#id/album_cover">
</TextView>
<TextView
android:id="#+id/number_of_albums"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#id/album_cover"
android:layout_toEndOf="#id/album_cover"
android:layout_below="#id/artist_name">
</TextView>
</RelativeLayout>
</RelativeLayout>
I need to center a textview just below an image view.
This is a row screenshot from what I a getting now:
I need to put the textview with the text "30" below the image view with the thumbs up hand, and centered. The height position is fine as it is now.
Like this:
This is my layout file:
<?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="wrap_content"
android:background="#5981b2"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="2dp"
android:src="#drawable/facebook" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/valoracion" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView2"
android:layout_centerHorizontal="true"
android:text="30"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:lines="2"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_toRightOf="#id/imageView1"
/>
</RelativeLayout>
Any help is welcome.
Remove this line
android:layout_centerHorizontal="true"
and add
android:layout_alignParentRight="true"
and you are good to go
If you don't wanna use margins, which can behave differently on other screens, you could for example use the TextView with an compoundDrawable like this:
<?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="wrap_content"
android:background="#5981b2"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="2dp"
android:src="#drawable/facebook" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:text="30"
android:drawablePadding="10dp"
android:gravity="center"
android:drawableTop="#drawable/valoracion"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:lines="2"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_toRightOf="#id/imageView1"
/>
</RelativeLayout>
Take away
android:layout_centerHorizontal="true"
The "below" is good. Then use
android:layout_toLeftOf="#id/imageView2"
android:layout_marginLeft="xxdp"
Set the margin until it appears correct.
Try this..
Remove android:layout_centerHorizontal="true" add android:layout_alignParentRight="true" and give android:layout_marginRight="15dp" for textView3 TextView
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView2"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:text="30"
android:textAppearance="?android:attr/textAppearanceSmall" />
How can I vertically centre the image in the example depicted below?
I need it to look like this:
The layout I'm using is as follows:
<RelativeLayout
android:id="#+id/layoutBranding"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/banner"
android:layout_margin="7dp">
<ImageView
android:id="#+id/imgInstallerLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:src="#drawable/logonarrow"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/txtInstallerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[Installer Description]"
android:textSize="20sp"
android:layout_toRightOf="#id/imgInstallerLogo"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/txtIntallerPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[Installer Phone Number]"
android:textSize="15sp"
android:layout_below="#id/txtInstallerName"
android:layout_toRightOf="#id/imgInstallerLogo" />
</RelativeLayout>
Remove the android:layout_alignParentTop="true" row.
Remove android:layout_alignParentTop="true" from xml in ImageView.
Updated code
<ImageView
android:id="#+id/imgInstallerLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:src="#drawable/logonarrow"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
Remove the android:layout_alignParentTop="true" from your ImageView.
<ImageView
android:id="#+id/imgInstallerLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:src="#drawable/logonarrow"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
Try the below code
<ImageView
android:id="#+id/imgInstallerLogo"
android:layout_width="60dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="7dp"
android:src="#drawable/logonarrow" />
This should work
Use this:
<RelativeLayout
android:id="#+id/layoutBranding"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/banner"
android:layout_margin="7dp">
<ImageView
android:id="#+id/imgInstallerLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:src="#drawable/logonarrow"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/txtInstallerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[Installer Description]"
android:textSize="20sp"
android:layout_toRightOf="#id/imgInstallerLogo"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/txtIntallerPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[Installer Phone Number]"
android:textSize="15sp"
android:layout_below="#id/txtInstallerName"
android:layout_toRightOf="#id/imgInstallerLogo" />
</RelativeLayout>
Remove the *android:layout_alignParentTop="true"* from your ImageView.
I have used relative layout and scrollview in my xml file.
When i click "Get Meaning " button i get the description of command but the data gets overlapped.Plz suggest some solution.
My layout xml file is:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/img7"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="490dip"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text=""
android:background="#drawable/house1" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentLeft="true"
android:text="Enter Unix Command"
android:textColor="#FF0000"
android:textSize="25sp"
/>
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="14dp"
android:ems="10"
android:hint="Start Typing Here........"
android:textColor="#FF0000" >
<requestFocus />
</AutoCompleteTextView>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/autoCompleteTextView1"
android:text="Get Meaning"
android:drawableLeft="#drawable/searchpic1"
android:textColor="#FF0000"
android:textSize="20sp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/button2"
android:src="#drawable/book1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1"
android:text=""
android:textColor="#FF0000"
/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Cympac Software Solutions Pvt Ltd"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#228b22"
android:background="#FFFFFF"
android:textStyle="bold"
android:textSize="16sp"
android:drawableLeft="#drawable/smallicon"/>
</RelativeLayout>
</ScrollView>
and on emulator its like
As Orabig said put only textview2 in ScrollView and and it should be above to the textview3. And Use RelativeLayout as a parent layout. Follow the code from Other two answers.I hope it will work
add property of layout_above for textview
change code like this
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1"
android:layout_above="#+id/textView3"
android:text=""
android:textColor="#FF0000"
/>
and then add scrollable property for that textview
yourTextView.setMovementMethod(new ScrollingMovementMethod());
it will scrolls automatically if the text requires more space than available.
Simply put your TextView into a ScrollView
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_above="#+id/textView3"
>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#FF0000"
/>
</ScrollLayout>