Android: Custom preference remove unwanted padding/margin? - android

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>

Related

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

ListView Row Layout Pushing ImageButton Off Screen

I am trying to create a Row layout to use in my ListView,
but when the text is too long, it pushes the right hand side ImageButton off the screen.
I want the text to just continue on the next line without interfering with the ImageButton-
This is the layout I have so far, I tried adding weight properties to set how much space could be use but I couldn't get it to work.
<?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="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:drawableTop="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thank You.
No matter what lenght if text, first and last image will be of width 50dp occupied, rest space for text.
<LinearLayout
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:drawableTop="#drawable/ic_launcher" />
</LinearLayout>
You're using too many LinearLayouts, and also you're not defining any constrain for your views space.
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" >
<ImageView
android:id="#+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:drawableTop="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/LinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/ImageButton"
android:layout_toRightOf="#id/ImageView"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</RelativeLayout>

Android Title + Button in titlebar not coming properly aligned

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>

i am unable to lock some part of the screen while using "Scroll View"

i am implementing one data enter screen with many fields.so that i am using scrolling view in my layout.But i want to draw OK button always.but i am unable to lock the some part of the screen.
i need secreen as:
but i am getting picture as either
or
i am adding my layout code below(as shown in last pic) plesae help me .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#2E9AFE" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Present Details"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColorHint="#350924"
android:textStyle="bold" />
<TextView
android:id="#+id/tvtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Present Location"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<EditText
android:id="#+id/etPreLoc1"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_gravity="center"
android:ems="10"
android:hint="Where are u now?"
android:inputType="textPostalAddress" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/etPreLoc1"
android:layout_gravity="center"
android:text="Coming By"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<EditText
android:id="#+id/mmsComing"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="car/auto/other" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Vehicle details"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<EditText
android:id="#+id/etDriver"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="Driver name/vehicle no"
android:inputType="textPersonName" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Expected time to reach by:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#350924"
android:textStyle="bold" />
<TimePicker
android:id="#+id/timePicker2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="75" />
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/mmsOk"
android:layout_width="fill_parent"
android:layout_height="64dp"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="25"
android:background="#drawable/blackbutton"
android:text="OK"
android:textColor="#android:color/white"
android:textSize="32dp"
android:textStyle="bold" />
</LinearLayout>
You can do that with a RelativeLayout like that. Just put all you views in the linearlayout inside the scrollview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
Change scrollview height to 0dp and give weight as 1.
Change button layout gravity to bottom instead of center.

problem with android UI

in my app i have a application bar at the top and an tab bar at the bottom. These two are been fixed. Inbetween of them i have place a ViewFipper. Inside the view flipper i have 7 text views, one image views and an 3 image buttons.
Now my problem is i want to show all these inside the space between the application bar and the tab bar in all devices. When i check the layout with 2.7 in QVGA the last buttons get hided behind the tab bar. Whereas in 3.2 in HVGA(ADP2) there are more spaces between the last two image buttons and the tab bar. I want the contents inside the view flipper to be exactly in the middle space, there should not be any scroll view in my layout. How to get this....
Following id my layout design
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#drawable/back" xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout android:layout_width="fill_parent" android:layout_marginBottom="10dp"
android:background="#drawable/graybar" android:layout_height="wrap_content"
android:id="#+id/relativeLayout2">
<TextView android:text="Detail" android:id="#+id/textView1"
android:textSize="24sp" android:layout_centerInParent="true"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
<TextView android:layout_width="wrap_content" android:text="Share Festival"
android:gravity="center" android:textStyle="bold"
android:layout_height="wrap_content" android:id="#+id/DetailShare"
android:layout_alignParentRight="true" android:background="#drawable/share">
</TextView>
</RelativeLayout>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_below="#+id/relativeLayout2" android:layout_above="#+id/relativeLayout4"
android:id="#+id/flipper" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:id="#+id/RLL"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical" android:layout_marginBottom="10dp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/LL" android:gravity="center">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/imageView1"
android:src="#drawable/p144" android:layout_alignParentTop="true">
</ImageView>
</LinearLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_below="#+id/LL" android:layout_height="wrap_content"
android:id="#+id/RL1">
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/detailback"
android:layout_alignParentLeft="true" android:background="#drawable/left">
</ImageButton>
<TextView android:text="Detail" android:id="#+id/textView1"
android:background="#drawable/share" android:textSize="15sp"
android:layout_centerInParent="true" android:gravity="center"
android:maxLines="2" android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TextView>
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/DetailShare"
android:layout_alignParentRight="true" android:background="#drawable/right">
</ImageButton>
</RelativeLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/Lq1" android:layout_below="#+id/RL1">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/L2">
<TextView android:text="date" android:id="#+id/date"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/L2">
<TextView android:text="Contact : " android:id="#+id/contact"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/L2">
<TextView android:text="mail" android:id="#+id/mail"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/L2">
<TextView android:text="phone" android:id="#+id/phone"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/L2">
<TextView android:text="Hollywood" android:id="#+id/address"
android:textSize="18sp" android:layout_marginTop="5dp" android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/L2">
<TextView android:text="DeadLine : closed 2011 festival"
android:id="#+id/date" android:textSize="18sp"
android:layout_marginTop="5dp" android:layout_gravity="center" android:layout_height="wrap_content"
android:layout_width="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="#+id/L2">
<TextView android:text="Genre" android:id="#+id/genre"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
</LinearLayout>
</LinearLayout>
<RelativeLayout android:id="#+id/Relativelayoutadd" android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_below="#+id/Lq1" android:layout_alignBaseline="#+id/flipper">
<TextView android:text="Add to IPhone calendar" android:id="#+id/calendar"
android:textSize="15sp" android:layout_marginBottom="5dp"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
<TextView android:text="Add to favorite" android:id="#+id/addtofavorite"
android:textSize="15sp" android:layout_marginBottom="5dp"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</TextView>
</RelativeLayout>
</RelativeLayout>
</ViewFlipper>
<RelativeLayout android:layout_width="fill_parent"
android:layout_gravity="bottom" android:layout_alignParentBottom="true"
android:background="#drawable/applicarion_bar" android:layout_height="wrap_content"
android:id="#+id/relativeLayout4">
<ImageButton android:layout_width="wrap_content"
android:layout_marginLeft="5dp" android:layout_height="wrap_content"
android:id="#+id/detailfestivallist" android:layout_alignParentLeft="true"
android:background="#drawable/festival_btn">
</ImageButton>
<ImageButton android:layout_width="wrap_content"
android:layout_marginLeft="90dp" android:layout_height="wrap_content"
android:id="#+id/detailsearch" android:layout_alignParentLeft="true"
android:background="#drawable/search_btn">
</ImageButton>
<TextView android:layout_width="wrap_content" android:text="MAR 20"
android:textSize="9sp" android:layout_marginLeft="170dp"
android:layout_height="wrap_content" android:id="#+id/detailcalendar"
android:layout_alignParentLeft="true" android:background="#drawable/calendar_btn">
</TextView>
<ImageButton android:layout_width="wrap_content"
android:layout_marginRight="5dp" android:layout_height="wrap_content"
android:id="#+id/detailfavorite" android:layout_alignParentRight="true"
android:background="#drawable/favorite_btn">
</ImageButton>
</RelativeLayout>
</RelativeLayout>
First, you have two different elements called android:id="#+id/date". This might give conflicts, and awkward behavior.
Secondly, the android:id="#+id/RLL" is only used to position items vertically. Therefore consider using a LinearLayout instead.
In general, I think your layout uses too much containers. I've created another layout (and replaced the drawables with colours, since i don't have the drawables) which you might use for inspiration to create a simpler, and flexible layout. As commented by Siva K, you can use the android:layout_weight="1" for the elements in the center (in the LinearLayout) to space them evenly...
Below is an example (only the viewFlipper part, the rest is unchanged)
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_below="#+id/relativeLayout2" android:layout_above="#+id/relativeLayout4"
android:id="#+id/flipper" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/RLL"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- HEADER IMAGE -->
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/imageView1"
android:src="#ff5500" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
</ImageView>
<!-- TOP -->
<TextView android:text="Detail" android:id="#+id/textView1"
android:background="#ff0022" android:textSize="15sp"
android:layout_centerInParent="true" android:gravity="center"
android:maxLines="2" android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/imageView1">
</TextView>
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/detailback"
android:layout_alignParentLeft="true" android:background="#112233"
android:layout_alignTop="#id/textView1">
</ImageButton>
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/DetailShare"
android:layout_alignParentRight="true" android:background="#55ff22"
android:layout_alignTop="#id/textView1">
</ImageButton>
<!-- MIDDLE -->
<LinearLayout
android:id="#+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/textView1"
android:orientation="vertical"
android:layout_marginBottom="20dp">
<TextView android:text="date" android:id="#+id/date"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1">
</TextView>
<TextView android:text="Contact : " android:id="#+id/contact"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1">
</TextView>
<TextView android:text="mail" android:id="#+id/mail"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1">
</TextView>
<TextView android:text="phone" android:id="#+id/phone"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1">
</TextView>
<TextView android:text="Hollywood" android:id="#+id/address"
android:textSize="18sp" android:layout_marginTop="5dp" android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1">
</TextView>
<TextView android:text="DeadLine : closed 2011 festival"
android:id="#+id/date2" android:textSize="18sp"
android:layout_marginTop="5dp" android:layout_gravity="center" android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1">
</TextView>
<TextView android:text="Genre" android:id="#+id/genre"
android:textSize="18sp" android:layout_marginTop="5dp"
android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_centerHorizontal="true" android:layout_weight="1">
</TextView>
</LinearLayout>
<!-- BOTTOM -->
<TextView android:text="Add to IPhone calendar" android:id="#+id/calendar"
android:textSize="15sp" android:layout_marginBottom="5dp"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentBottom="true">
</TextView>
<TextView android:text="Add to favorite" android:id="#+id/addtofavorite"
android:textSize="15sp" android:layout_marginBottom="5dp"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentBottom="true">
</TextView>
</RelativeLayout>
</ViewFlipper>
Hope this works for you.

Categories

Resources