Layouts appears differently on real device - android

The layout I'm designing appears fine in graphical layout but when I install it on the device it screws up.
Graphical Layout
On device
Here is my layout file.
<?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:background="#drawable/home_background"
>
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout1"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="81dp"
android:scrollbars="none"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:src="#drawable/flipkart" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/dominos" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/flipkart" />
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/dotted_separator"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout1"
android:layout_marginTop="17dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:src="#drawable/dotted_separator" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="30dp" >
<LinearLayout
android:id="#+id/title_holder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/find_restaurant_coupons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Find Restaurant Coupons"
android:textColor="#ffffff"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/spinner_holder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/title_holder"
>
<!--
<Spinner
android:id="#+id/city_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/city_spinner_data"
/>
-->
</LinearLayout>
<LinearLayout
android:id="#+id/location_search_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner_holder"
>
<EditText
android:id="#+id/input_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:ems="10"
android:hint="Location"
android:inputType="text"
android:padding="10dp"
android:textColor="#000000" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/input_location"
android:background="#17b851"
android:padding="10dp"
android:text="GO" />
</LinearLayout>
</RelativeLayout>
<Button
android:id="#+id/best_restaurants_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/horizontalScrollView1"
android:layout_marginBottom="14dp"
android:layout_marginRight="42dp"
android:background="#17b851"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:text="Best Restaurants Offers" />
</RelativeLayout>

I dont understand what the problem was. I again stared with a blank file and copied each block one at a time to narrow down the problem but to my surprise this time it shows up properly.

Related

Android - Supporting Multiple Screens

I have made a simple application, with a background image, 4 image buttons and 4 text views in front of them.
I've read the google development documentation, but I still don't understand why in screens with a different size of 4,7" the app doesn't run normally. The textview is not in the right place. The image buttons are too small or too big in wrong places
I've created different images for differente resolutions (ldpi, mdpi, hdpi,xhdpi).
Here is the xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gameinterface"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".QuestionsActivity" >
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="95dp"
android:layout_marginRight="10dp"
android:layout_marginTop="137dp"
android:orientation="vertical" >
<TextView
android:id="#+id/tvQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_vertical|center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" >
<TextView
android:id="#+id/tvNumQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#B22222"
android:textSize="30sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/20"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#B22222"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout3"
android:layout_alignLeft="#+id/linearLayout4"
android:layout_marginBottom="114dp" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/btnR1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:src="#drawable/answerbutton" />
<TextView
android:id="#+id/tvR1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" >
<ImageButton
android:id="#+id/btnR3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:src="#drawable/answerbutton" />
<TextView
android:id="#+id/tvR3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/btnR2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:src="#drawable/answerbutton" />
<TextView
android:id="#+id/tvR2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" >
<ImageButton
android:id="#+id/btnR4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:src="#drawable/answerbutton" />
<TextView
android:id="#+id/tvR4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

Using two google map v2 objects in App

I'm trying to use two maps in my application where I have just one activity and several fragments displaying in different tabs. I have one fragment where the map covers the entire layout and another which is just in a small section of the layout.
The first one works fine I but adding the second map causes my app to crash giving an inflation exception.
Here are xml layouts.
Fist xml 1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:focusable="true"
android:focusableInTouchMode="true" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/grey"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/search_bar"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<ImageButton
android:id="#+id/button3"
android:layout_width="#dimen/title"
android:layout_height="#dimen/title"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/search"
android:contentDescription="#string/search" />
<AutoCompleteTextView
android:id="#+id/location_search"
android:layout_width="wrap_content"
android:layout_height="#dimen/etext_height"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/search_cancel"
android:layout_toRightOf="#+id/button3"
android:background="#00ffffff"
android:hint="#string/search_msg"
android:inputType="text"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:popupBackground="#drawable/drop_down_bg"
android:textColor="#color/text_grey"
android:textSize="#dimen/stat_tx" >
</AutoCompleteTextView>
<Button
android:id="#+id/search_cancel"
android:layout_width="#dimen/title"
android:layout_height="#dimen/title"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/pop_up_close" />
</RelativeLayout>
</RelativeLayout>
<FrameLayout
android:id="#+id/frameline"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/relativeLayout1"
android:background="#color/light_pink" >
</FrameLayout>
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/frameline"
class="com.app.custom.views.TransparentSupportMapFragment" />
XML 2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/grey"
android:paddingTop="3dp" >
<FrameLayout
android:id="#+id/frameLayout13"
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/divider" >
</FrameLayout>
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/frameLayout13"
android:background="#drawable/title_bg" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="10dp"
android:text="#string/description"
android:textColor="#color/text_grey"
android:textSize="#dimen/event_list_text_large" />
</FrameLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_frame"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/frameLayout1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_alignRight="#+id/linearLayout1"
android:layout_below="#+id/linearLayout1"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp" >
<TextView
android:id="#+id/club_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/relativeLayout1"
android:textColor="#color/light_pink"
android:textIsSelectable="false"
android:textSize="#dimen/event_list_text_large" />
<TextView
android:id="#+id/show_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/event_name"
android:layout_marginTop="-3dp"
android:textColor="#color/text_grey_dark"
android:textIsSelectable="false"
android:textSize="#dimen/event_list_text_large" />
<TextView
android:id="#+id/event_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/club_name"
android:paddingTop="4dp"
android:textColor="#color/text_grey_dark"
android:textIsSelectable="false"
android:textSize="#dimen/event_list_text_large" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<TextView
android:id="#+id/event_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#color/text_grey_dark"
android:textIsSelectable="false"
android:textSize="#dimen/title"
android:textStyle="bold" />
<TextView
android:id="#+id/event_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textColor="#color/light_pink"
android:textIsSelectable="false"
android:textSize="#dimen/event_list_text_small" />
<TextView
android:id="#+id/event_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="-3dp"
android:drawableLeft="#drawable/clock"
android:drawablePadding="5dp"
android:textColor="#color/light_pink"
android:textIsSelectable="false"
android:textSize="#dimen/event_list_text_small" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="#dimen/event_row_height2"
android:layout_alignLeft="#+id/relativeLayout1"
android:layout_alignRight="#+id/relativeLayout1"
android:layout_below="#+id/venue_address"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:background="#fff" >
<fragment
android:id="#+id/map22"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="-50dp"
android:layout_marginRight="-50dp"
class="com.fixr.custom.views.TransparentSupportMapFragment" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Is it the same process for using two maps as it is for using one or is there something different I need to do.
I am pretty sure that you cannot draw a map inside a <ScrollView>.
I would also recommend trying not to use the negative margin on the Map.
P.S. You have a lot of extra components in your layout that do not need to be there and you should find that reducing them will improve your app's performance.
Examples:
1)
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/frameLayout13"
android:background="#drawable/title_bg" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="10dp"
android:text="#string/description"
android:textColor="#color/text_grey"
android:textSize="#dimen/event_list_text_large" />
</FrameLayout>
can changed to:
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/frameLayout13"
android:layout_gravity="center"
android:background="#drawable/title_bg"
android:gravity="center"
android:padding="10dp"
android:text="#string/description"
android:textColor="#color/text_grey"
android:textSize="#dimen/event_list_text_large" />
2) Dividers on need to need to be a plain <View>
<FrameLayout
android:id="#+id/frameLayout13"
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/divider" >
</FrameLayout>
can be changed to:
<View
android:id="#+id/frameLayout13"
android:layout_width="wrap_content"
android:layout_height="0.5dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/divider" />

ListView pushes button out of screen

I'm trying to get the ListView to remain the same size even if it overflows. However, once the ListView overflows, it pushes the buttons below off the screen. How do I prevent it from pushing other elements that are below it?
As you can see from the above images, the second shows that the buttons get pushed off the screen once the ListView overflows.
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/splash_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:background="#color/splash_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp"
android:paddingBottom="10dp"
android:textColor="#color/splash_text"
android:text="#string/sub" />
<EditText
android:id="#+id/grp_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/field1"
android:lines="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/members"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textSize="15sp"
android:paddingTop="5dp"
android:textColor="#color/splash_text"
android:text="#string/members" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/splash_bg"
android:orientation="horizontal" >
<EditText
android:id="#+id/name"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/field2" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingTop="10dp" >
<Button
android:id="#+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="Save" />
<Button
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
Changet
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
to
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
You can use a relative layout for this. Modify the below according to your needs
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="11dp"
android:layout_marginTop="11dp"
android:text="Create New Group" />
<EditText
android:id="#+id/editText1"
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="23dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText1"
android:layout_marginLeft="11dp"
android:layout_marginTop="18dp"
android:text="Members" />
<EditText
android:id="#+id/editText2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/textView1"
android:layout_below="#+id/textView2"
android:layout_marginTop="31dp"
android:ems="10" />
<ListView
android:id="#android:id/list"
android:layout_above="#+id/button1"
android:layout_below="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
/>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignBottom="#+id/editText2"
android:layout_alignParentRight="true"
android:layout_marginRight="13dp"
android:text="ADD" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button3"
android:layout_below="#android:id/list"
android:text="Cancel" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/textView1"
android:text="Save" />
</RelativeLayout>
I added this line : android:layout_weight="1" to the LinearLayout where EditText exist (my problem source) and the problem is gone !
look at the code where I commented <!-- HERE!!! -->
LOL I know i'm very late to answer this Q ,, sorry ,, but for anyone who is still struggling !
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linearLayout1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="ID : "
android:layout_margin="#dimen/EdgeMargins"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText"
android:layout_margin="#dimen/EdgeMargins"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayout2"
android:layout_weight="1"> <!-- HERE!!! -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Any Notes :"
android:id="#+id/textView2"
android:layout_margin="#dimen/EdgeMargins"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_margin="#dimen/EdgeMargins" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:id="#+id/button"
android:layout_margin="#dimen/EdgeMargins" />
</LinearLayout>
i had my problem with the highlighted EditText in the pic ,,, it expands with the entered text and pushes the DONE Button down !
I know my solution may look so silly but I took a whole day to solve this !
Hope it helps ^_^ GL

Fragment inside ScrollView gives black background flickering

I have a LinearLayout in one of the activities as the main layout. I used Scrollview to encapsulated the LinearLayout. The Layout contains a fragment which displays a google map, but on scrolling it gave black background. I resolved the issue by using a transparent background inside a FrameLayout. The black background has gone, but during scrolling i get flickering black edges around the map. How to remove this? I tried setting the background of Scrollview to white color, but no change visible.
The XML of the activity is --
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:baselineAligned="false"
android:orientation="vertical"
android:overScrollMode="ifContentScrolls"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical"
android:showDividers="none" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#ec4d1d" >
<TextView
android:id="#+id/friend_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="7dp"
android:background="#drawable/near_you_bg"
android:gravity="center_horizontal|center_vertical"
android:padding="6dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
<Button
android:id="#+id/btnInviteFriends"
android:layout_width="30dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="7dp"
android:background="#drawable/menu_bg"
android:onClick="inviteFriends" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="81dp"
android:background="#drawable/list_bg"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginTop="4dp"
android:gravity="center_vertical|center_horizontal" >
<RelativeLayout
android:layout_width="65dp"
android:layout_height="70dp" >
<ImageView
android:id="#+id/user_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="7dp"
android:src="#drawable/d_bg" />
</RelativeLayout>
<RelativeLayout
android:layout_width="140dp"
android:layout_height="70dp" >
<TextView
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_toRightOf="#id/user_image"
android:paddingBottom="2dip"
android:text="Amrinder"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/distance"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/name"
android:layout_marginTop="2dp"
android:layout_toRightOf="#id/user_image"
android:text="description"
android:textColor="#000000"
android:textSize="10sp" >
</TextView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/distance"
android:layout_marginTop="7dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/common_icon"
android:layout_width="26dp"
android:layout_height="19dp"
android:background="#drawable/common_icon" />
<TextView
android:id="#+id/common_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="4"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="#+id/friends_icon"
android:layout_width="26dp"
android:layout_height="19dp"
android:layout_marginLeft="7dp"
android:background="#drawable/friends_icon" />
<TextView
android:id="#+id/friends_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="5"
android:textColor="#000000"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/nearUserInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible" >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/time_ago"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10 min ago"
/>
<ImageView
android:id="#+id/dir_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time_ago"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:background="#drawable/say_hi_button" />
</RelativeLayout>
</TableRow>
</TableLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
>
<ImageView
android:id="#+id/map_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:layout_centerInParent="false"
android:layout_gravity="center_horizontal"
android:background="#drawable/map_box_bg" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="25dp" >
<TextView
android:id="#+id/distance_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="1dp"
android:text="X is 4 km north-east of you now"
android:textColor="#ffffff"
android:textStyle="bold" />
</RelativeLayout>
<FrameLayout
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_below="#id/map_bar"
/>
<View
android:id="#+id/trans_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/trans" />
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<ImageView
android:id="#+id/like_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:layout_gravity="center_horizontal"
android:background="#drawable/map_box_bg" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="25dp" >
<ImageView
android:id="#+id/like_button"
android:layout_width="24dp"
android:layout_height="23dp"
android:layout_centerVertical="true"
android:layout_marginLeft="1dp"
android:background="#drawable/common_detail_icon" />
<TextView
android:id="#+id/likes_in_common"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/like_button"
android:gravity="center_vertical"
android:text=" 3 likes in common"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:id="#+id/like_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/like_bar"
android:layout_gravity="center_horizontal"
android:background="#drawable/list_bg" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<ImageView
android:id="#+id/friends_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:layout_gravity="center_horizontal"
android:background="#drawable/map_box_bg" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="25dp"
android:layout_alignParentRight="true" >
<ImageView
android:id="#+id/friends_button"
android:layout_width="24dp"
android:layout_height="23dp"
android:layout_centerVertical="true"
android:layout_marginLeft="1dp"
android:background="#drawable/common_friends_icon" />
<TextView
android:id="#+id/friends_in_common"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/friends_button"
android:gravity="center_vertical"
android:text=" 9 friends in common"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:id="#+id/friends_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/friends_bar"
android:layout_gravity="center_horizontal"
android:background="#drawable/list_bg" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<ImageView
android:id="#+id/friends_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:layout_gravity="center_horizontal"
android:background="#drawable/map_box_bg" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="25dp"
android:layout_alignParentRight="true" >
<ImageView
android:id="#+id/friends_button"
android:layout_width="24dp"
android:layout_height="23dp"
android:layout_centerVertical="true"
android:layout_marginLeft="1dp"
android:background="#drawable/common_friends_icon" />
<TextView
android:id="#+id/friends_in_common"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/friends_button"
android:gravity="center_vertical"
android:text=" 9 friends in common"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:id="#+id/friends_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/friends_bar"
android:layout_gravity="center_horizontal"
android:background="#drawable/list_bg" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" >
<ImageView
android:id="#+id/friends_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:layout_gravity="center_horizontal"
android:background="#drawable/map_box_bg" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="25dp"
android:layout_alignParentRight="true" >
<ImageView
android:id="#+id/friends_button"
android:layout_width="24dp"
android:layout_height="23dp"
android:layout_centerVertical="true"
android:layout_marginLeft="1dp"
android:background="#drawable/common_friends_icon" />
<TextView
android:id="#+id/friends_in_common"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/friends_button"
android:gravity="center_vertical"
android:text=" 9 friends in common"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:id="#+id/friends_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/friends_bar"
android:layout_gravity="center_horizontal"
android:background="#drawable/list_bg" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Instead of using a transparent image above the map fragment you try using the transparent color becauz i was also facing the same issue and i solved using this method.
android:background="#android:color/transparent"
But technically speaking as suggested by Android you should not use a scrolling element inside another scrolling element.Rather you can use the Google map static map API to show static map inside scroll view and when you tap on scroll view you can open a Scrollable google map in a new window.
The reason behind this is that the Map uses a SurfaceView, when the App creates this view it creates a Window behind your Activity's and punches a hole meaning things in your Activity's window cannot seen underneath the SurfaceView's original location.
For me this is worked like charm, You can use this library
https://github.com/NyxDigital/NiceSupportMapFragment/

Android Custom dialog inflating from layout - alignment issue

I have an custom dialog, whick i am inflating from dialog.xml. when I open the dialog it looks something like shown below. I am getting some space between listview and the (OK) button below it. I want to eliminate this space between the list view and the Button below it.
How can i do this,?
dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/listViewDialog"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button1"
android:layout_below="#+id/ImageView1" >
</ListView>
<CheckBox
android:id="#+id/checkBoxAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/listView1"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp"
android:text="" />
<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_marginBottom="15dp"
android:layout_marginLeft="14dp"
android:layout_marginTop="15dp"
android:background="#FFFFBB33"
android:contentDescription="#string/app_name"
android:scaleType="center"
android:src="#drawable/alert_dialog_icon" />
<TextView
android:id="#+id/textView1"
android:layout_width="128dp"
android:layout_height="match_parent"
android:layout_above="#+id/listViewDialog"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="#+id/ImageView1"
android:gravity="center_vertical"
android:text="Categories"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_toLeftOf="#+id/checkBoxAll"
android:text="All"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="OK" />
</RelativeLayout>
this is really easy..
you have 2 approchase:
1) create the root realtivelayout to have android:layout_height="wrap_cotent", and in the same time the ListView to have the same. this will shrink the sizes of the all dialog to the right (no space) size.
2) *more recomended , have the root to be a Linearlayout and give it some wightsum, then put the other views in this root, and give them some layout_wight, this way you know the in any screen resolution you have the same porportion of your screen.
maybe try like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="100" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="15" >
<CheckBox
android:id="#+id/checkBoxAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/listView1"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp" />
<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_marginBottom="15dp"
android:layout_marginLeft="14dp"
android:layout_marginTop="15dp"
android:background="#FFFFBB33"
android:contentDescription="#string/app_name"
android:scaleType="center" />
<TextView
android:id="#+id/textView1"
android:layout_width="128dp"
android:layout_height="match_parent"
android:layout_above="#+id/listViewDialog"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="#+id/ImageView1"
android:gravity="center_vertical"
android:text="Categories"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_toLeftOf="#+id/checkBoxAll"
android:text="All"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<ListView
android:id="#+id/listViewDialog"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="70" >
</ListView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="15" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="OK" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Categories

Resources