Android Title + Button in titlebar not coming properly aligned - android

I am trying to add title + button in titlebar in Android. But somehow i am not happy with the kind of result i am getting. May be something wrong with code. Has anyone tried this earlier ? My .xml is below
code.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#484848"
android:orientation="horizontal">
<TextView
android:id="#+id/windowtitle"
android:layout_width="match_parent"
android:layout_marginTop="2dip"
android:layout_height="wrap_content"
android:text="Support"
android:gravity="center_horizontal"
android:textSize="30sp" ></TextView>
<Button
android:id="#+id/syncbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="3dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="left"
android:text="Sync" />
</RelativeLayout>
</RelativeLayout>

Please mention exact issue you are facing, I assume the alignment of the two views is not proper is the issue.
You can give the relative position of the button with respect to the text view to the button xml,
android:layout_toRightOf="#+id/windowtitle"
Also, add the alignment to the textview

Replace your XML with below code..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#484848"
android:orientation="horizontal">
<TextView
android:id="#+id/windowtitle"
android:layout_width="fill_parent"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:text="Support"
android:gravity="center_horizontal|center_vertical"
android:textSize="30sp" ></TextView>
<Button
android:id="#+id/syncbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="3dip"
android:layout_alignParentRight="true"
android:text="Sync" />
</RelativeLayout>
</RelativeLayout>
Hope this work.....

Try this..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#484848">
<TextView
android:id="#+id/windowtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Support"
android:layout_centerHorizontal="true"
android:textSize="30sp" ></TextView>
<Button
android:id="#+id/syncbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Sync" />
</RelativeLayout>
</RelativeLayout>
Here is my screen

Remove android:gravity="center_horizontal" from windowtitle Textview and add android:layout_centerInParent="true" even change width to wrap_content.
and add android:layout_centerVertical="true" to syncbutton button and there is no need of android:layout_alignParentTop="true"
It all centered your views.
check below xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#484848"
android:orientation="horizontal" >
<TextView
android:id="#+id/windowtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="2dip"
android:text="Support"
android:textSize="30sp" >
</TextView>
<Button
android:id="#+id/syncbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginTop="3dip"
android:gravity="left"
android:text="Sync" />
</RelativeLayout>
</RelativeLayout>

Use this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#484848" >
<TextView
android:id="#+id/windowtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Support"
android:textSize="30sp" >
</TextView>
<Button
android:id="#+id/syncbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Sync" />
</RelativeLayout>

Use the following Code this might fullfill your requirement:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#484848"
android:orientation="horizontal">
<TextView
android:id="#+id/windowtitle"
android:layout_width="match_parent"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:text="Support"
android:gravity="center_horizontal"
android:textSize="30sp" ></TextView>
<Button
android:id="#+id/syncbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Sync" />
</RelativeLayout>
</RelativeLayout>

use this
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#484848"
android:orientation="horizontal">
<TextView
android:id="#+id/windowtitle"
android:layout_width="wrap_content"
android:layout_marginTop="2dip"
android:layout_height="wrap_content"
android:text="Support"
android:gravity="center_horizontal"
android:textSize="30sp" ></TextView>
<Button
android:id="#+id/syncbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:text="Sync" />
</RelativeLayout>

Related

Android: Custom preference remove unwanted padding/margin?

I am creating my own custom seekbar preference. But there is white space on left side of preference widget. How can I get rid of it?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/widget_frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/seekBarPrefUnitsRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"></TextView>
<TextView
android:id="#+id/seekBarPrefValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/seekBarPrefUnitsRight"
android:gravity="right"></TextView>
<TextView
android:id="#+id/seekBarPrefUnitsLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/seekBarPrefValue"></TextView>
<LinearLayout
android:id="#+id/seekBarPrefBarContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/seekBarPrefUnitsRight"
android:orientation="horizontal">
<SeekBar
android:id="#+id/seekBarPrefSeekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
I highlight with yellow unwanted space.
you can try to play with negative values of margin or padding on the individual element, depending on your desire.
Use below code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/widget_frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp" >
<TextView
android:id="#+id/tvCheckItOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingBottom="5dp"
android:text="Check it out"
android:textStyle="bold" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvCheckItOut"
android:text="Check it out" >
</TextView>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp" >
<TextView
android:id="#+id/tvSeekbarSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingBottom="5dp"
android:text="SeekBar"
android:textStyle="bold" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvSeekbarSummary"
android:text="Summary" >
</TextView>
</RelativeLayout>
<SeekBar
android:id="#+id/seekBarPrefSeekBar"
android:layout_width="fill_parent"
android:progress="100"
android:layout_height="wrap_content" />
</LinearLayout>

How to make text scroll and keep other elements fixed to the bottom of the screen?

I'm trying to create the following display, where the text scrolls and the other elements are fixed to the bottom of the screen:
However, it is appearing as follows, where the text doesn't scroll and it's pushing the elements off the screen.:
This is the layout I'm using:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ScrollView
android:id="#+id/scroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingLeft="20dp"
android:layout_alignParentLeft="true" />
</ScrollView>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:text="Don't Show Again"
android:layout_below="#+id/scroller" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/chkBox"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/imgCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="0dip"
android:src="#drawable/stop"
android:paddingBottom="5dip"
android:paddingRight="5dip"
android:background="#drawable/common_button" />
<TextView
android:id="#+id/txtCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/imgCancel"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="OK"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
What do I need to do to make the text scroll and the other elements fixed to the bottom of the screen?
Try replacing this xml code and apply images where you need
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#5555"
android:gravity="center"
android:orientation="vertical"
android:padding="25dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Terms and Conditions"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ScrollView
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView
android:id="#+id/txtTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="20dp"
android:textSize="20sp" />
</ScrollView>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/scroller"
android:layout_gravity="center_vertical"
android:text="Don&apos;t Show Again" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/chkBox"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/imgCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="0dip"
android:paddingBottom="5dip"
android:paddingRight="5dip" />
<TextView
android:id="#+id/txtCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/imgCancel"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="OK"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
You should add the ScrollView Containing the TextView inside a Layout(Linear would do). I hope it helps

linearlayout element and their position

I have a linearLayout with 2 elements, a textView and a imagebutton, I would like to center in the linearlayout the textView and right-aligment for the imageButto, but both of them are at left.
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#color/usualBike"
>
<TextView
android:id="#+id/usesLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:text="#string/tituloUsos"
android:textSize="30dip"
android:layout_gravity="center"
android:textStyle="bold"
/>
<ImageButton
android:id="#+id/disconnect"
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="#drawable/icon_logout" />
</LinearLayout>
how can I get it?
Are you particular about LinearLayout? if not why don't you try with RelativeLayout like this:
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#color/usualBike"
>
<TextView
android:id="#+id/usesLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/tituloUsos"
android:textColor="#color/white"
android:textSize="30dip"
android:textStyle="bold" />
<ImageButton
android:id="#+id/disconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#null"
android:gravity="right"
android:src="#drawable/icon_logout" />
</RelativeLayout>
try layout_gravity instead of gravity
Try this:
<?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"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<TextView
android:id="#+id/usesLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="tituloUsos"
android:textSize="30dip"
android:textStyle="bold" />
<ImageButton
android:id="#+id/disconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/usesLabel"
android:background="#null"
android:gravity="right"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</RelativeLayout>

RelativeLayout inside a ScrollView not working with Landscape Orientation

I need to have multiple textviews within a scrollview. I am using a relative layout as a container to all these textviews.
The layout looks fine in portrait orientation, but when in landscape orientation, the textview at the top of the relative layout within the scrollview (tvEx) is not visible. This is only when I test in the emulator for devices that have a small screen. Apart from this minor problem, the layout works perfectly well. Although, this seems to be a minor issue, somehow I am not able to get around it. Kindly help.
The layout file is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#drawable/background" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header" >
<Button
android:id="#+id/btBack"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/back"
android:visibility="invisible" />
<TextView
android:id="#+id/tvBanner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBaseline="#+id/btBack"
android:layout_alignBottom="#+id/btBack"
android:layout_alignParentLeft="true"
android:gravity="fill"
android:text="Practice Exam"
android:textColor="#android:color/white"
android:textSize="20sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/footer"
android:orientation="horizontal" >
<Button
android:id="#+id/btHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/home" />
</RelativeLayout>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/RelativeLayout1"
android:layout_below="#+id/Header"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center" >
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:gravity="center" >
<TextView
android:id="#+id/tvEx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentTop="true"
android:text="Congratulations!!"
android:textColor="#android:color/white"
android:textSize="24sp"/>
<TextView
android:id="#+id/tvRes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvEx"
android:gravity="center"
android:text="You passed"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvLuck"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvRes"
android:layout_margin="10dp"
android:gravity="center"
android:text="Great going"
android:textColor="#android:color/white"
android:textSize="18sp" />
<LinearLayout
android:id="#+id/lins"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_below="#+id/tvLuck"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCORE:"
android:textColor="#android:color/white"
android:textSize="24sp" />
<TextView
android:id="#+id/tvScoreNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tvScore"
android:layout_alignBaseline="#+id/tvScore"
android:textColor="#android:color/white"
android:textSize="28sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/tvCorr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lins"
android:layout_margin="10dp"
android:layout_marginTop="47dp"
android:gravity="center_horizontal"
android:text="Correct Answers:"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvIncorr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvCorr"
android:gravity="center_horizontal"
android:text="Incorrect Answers:"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvtot"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvIncorr"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Total Questions:"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I had a similar problem in a ScrollView. Try changing android:gravity="center" to android:gravity="center_horizontal" or removing it completely. Similar to ScrollView hides.

Showing a second TextView layout in Android

I am trying create a layout. There are several inner layouts that should like like this:
http://imageshack.us/photo/my-images/835/69560035.png/
So there is a main LinearLayout and several layouts inside like the one below.
<LinearLayout android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<ImageView android:id="#+id/ImageView01"
android:layout_width="30px"
android:layout_height="30px"
android:scaleType="fitXY"
android:background="#drawable/gy1"
android:layout_gravity="center_vertical">
</ImageView>
<LinearLayout android:id="#+id/LinearLayout04"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_gravity="center_vertical">
<TextView android:id="#+id/TextView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15px"
android:textStyle="bold"
android:textColor="#222222"
android:paddingLeft="3px">
</TextView>
<TextView android:id="#+id/TextView02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#222222"
android:paddingBottom="5px"
android:paddingLeft="3px"
android:background="#D8D8D8"
/>
</LinearLayout>
</LinearLayout>
The second TextView is not shown, and I cannot find out what is wrong with the code. How can I fix this problem?
Or try this:
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="30px"
android:layout_alignParentTop = "true"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:gravity="left">
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="left"
android:src="#drawable/gy1"
android:background="#null"
android:width="30px"
android:cropToPadding="true"
android:adjustViewBounds="true">
</ImageView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_toRightOf="#+id/RelativeLayout01">
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15px"
android:textStyle="bold"
android:textColor="#222222"
android:paddingLeft="3px">
</TextView>
<TextView
android:id="#+id/TextView02"
android:layout_below="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#222222"
android:paddingBottom="5px"
android:paddingLeft="3px"
android:background="#D8D8D8" >
</TextView>
</RelativeLayout>
</LinearLayout>
Use the following.
<LinearLayout android:id="#+id/LinearLayout02"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<ImageView android:id="#+id/ImageView01"
android:layout_width="30px" android:layout_height="30px"
android:scaleType="fitXY" android:background="#drawable/gy1"
android:layout_gravity="center_vertical">
</ImageView>
<LinearLayout android:id="#+id/LinearLayout04"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center_vertical">
<LinearLayout android:id="#+id/LinearLayout04"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:id="#+id/TextView01" android:layout_width="fill_parent"
android:textSize="15px" android:textStyle="bold" android:textColor="#222222"
android:paddingLeft="3px" android:layout_alignParentTop="true"
android:text="Hello" android:layout_height="fill_parent">
</TextView>
</LinearLayout>
<LinearLayout android:id="#+id/LinearLayout04"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:id="#+id/TextView02" android:layout_width="fill_parent"
android:textColor="#222222" android:paddingBottom="5px"
android:paddingLeft="3px" android:background="#D8D8D8"
android:layout_below="#+id/TextView01" android:text="Hello 2222"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:src="#drawable/icon" />
<TextView
android:id="#+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="#id/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Simple application that shows how to use RelativeLayout" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/icon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="#id/secondLine"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="My Application" />
</RelativeLayout>
This technique in Android Layout Tricks #1 may solve your problem.

Categories

Resources