Using two google map v2 objects in App - android

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" />

Related

how to set vertically scrolling ScrollView withinanother vertically scrolling widget (ListView)

I am having trouble with a scrolling ListView inside a ScrollView.I have tried the code given bellow.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linlaypromodet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearlayoutheaderpromo"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="#drawable/dairam_header2">
<Button
android:id="#+id/buttonbackhomepromodet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back_arrow"
android:layout_marginLeft="3dp"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp">
<TextView
android:id="#+id/textviewheaderpromodete"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:textColor="#fff"
android:layout_marginLeft="4dp"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/buttonsharepromodet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="30dp"
android:layout_marginRight="10dp"
android:background="#drawable/shareicon" />
</RelativeLayout>
</LinearLayout> <ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/buttoncartpromodet"
android:layout_weight="2"
android:layout_marginTop="5dp" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="100dp" >
<com.dairam.viewpager.AutoScrollViewPager
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:minHeight="100dp"
android:layout_alignParentTop="true"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="75dp" >
<Button
android:id="#+id/buttonleftarrow"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_alignParentLeft="true"
android:background="#drawable/arrow_leftgray" />
<Button
android:id="#+id/buttonrightarrow"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:background="#drawable/arrow_rightgray" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/rellay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout android:id="#+id/toplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<Button android:id="#+id/viewbtn"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginTop="5dp"
android:background="#drawable/dividergray"/>
<Button
android:id="#+id/buttoncartpromodet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="5dp"
android:background="#drawable/redicon"/>
<Button
android:id="#+id/buttonwishlistpromodet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="8dp"
android:layout_toLeftOf="#+id/buttoncartpromodet"
android:background="#drawable/greenicon" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttonwishlistpromodet"
android:layout_alignBottom="#+id/buttonwishlistpromodet"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:textColor="#000"/>
<ScrollView
android:id="#+id/scrollViewdesc"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:layout_marginTop="5dp" > <ListView
android:id="#+id/textViewdescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp"
>
</ListView> </ScrollView>
<Button android:id="#+id/dividerbtm"
android:layout_height="2dp"
android:layout_width="fill_parent"
android:background="#drawable/dividergray"
android:layout_alignBottom="#+id/textViewdescription"
android:layout_marginTop="5dp"/>
</RelativeLayout>
<TextView
android:id="#+id/textviewsuggestion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="YOU MAY ALSO LIKE"
android:textColor="#000"
android:textSize="20sp" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#fff" >
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<View android:layout_height="1dp"
android:layout_width="fill_parent"
android:background="#drawable/dividergray"
android:layout_marginTop="6dp"/>
<Button
android:id="#+id/buttonamntpromodet"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp"
android:textColor="#fff"
android:background="#drawable/redbox" />
<Spinner
android:id="#+id/buttonquantitypromodet"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#fff"
android:spinnerMode="dropdown"
android:gravity="center"
android:paddingLeft="10dp"
android:layout_alignParentRight="true"
android:background="#drawable/greybox2" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/buttonquantitypromodet"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="3dp"
android:text=" Quantity"
android:gravity="center"
android:textColor="#fff"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</LinearLayout>
What you're doing wrong (to my knowledge) is putting the listView inside a ScrollView. ListView by itself is inherantly scrollable, so the scrollview is not necessary.
I've had issues myself in the past where it causes neither to scroll.... perhaps that is your issue.
Also, I don't know if its just how you posted the code but you shouldn't start a layout with a button.... i believe it needs to be set inside a layout tag.
Please Remove Scroll View from above Listview Because Listvie itself scrollable.

Layouts appears differently on real device

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.

How to create a login form in Android?

I want to create a login form. But i am new in android so i am not able to do it properly. I have to put the logo of the company on it's header. After that the heading will be Like Login to you are account after that in a box the user name and password. So i am posting my xml please upadte it. Thanks...
This is how i have to create it from this link please check this
http://s23.postimg.org/btie12dvv/Login_Page2.jpg
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#5F04B4"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="User Name"
android:textColor="#ffffff"
android:textSize="13dp"
android:textStyle="bold" />
<EditText
android:id="#+id/edtUserName"
android:layout_width="200dp"
android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Password"
android:textColor="#ffffff"
android:textSize="13dp"
android:textStyle="bold" />
<EditText
android:id="#+id/edtPassword"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:password="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<Button
android:id="#+id/btnLogin"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Login" />
</LinearLayout>
</LinearLayout>
For setting company logo in header:
getActionBar().setHomeButtonEnabled(true);
Drawable d=getResources().getDrawable(R.drawable.company_logo.png);
getActionBar().setBackgroundDrawable(d);
For setting title: Login
getActionBar().setTitle("Login");
I hope it will help you.
I created a sample code. You need to replace proper images with sample one.
layout code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="#+id/imgLogo"
android:background="#092EA1"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="Login to Your Account"
android:textColor="#android:color/white"
android:textSize="25sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="260dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="17dp"
android:layout_marginTop="15dp"
android:background="#android:color/darker_gray" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignLeft="#+id/imageView1"
android:layout_alignRight="#+id/imageView1"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="40dp"
android:hint="Usrname" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="260dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1"
android:layout_marginLeft="17dp"
android:layout_marginTop="15dp"
android:background="#android:color/darker_gray" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView2"
android:layout_alignLeft="#+id/imageView2"
android:layout_alignRight="#+id/imageView2"
android:layout_alignTop="#+id/imageView2"
android:layout_marginLeft="40dp"
android:hint="Password"
android:inputType="textWebPassword" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView2"
android:layout_below="#+id/imageView2"
android:layout_marginTop="26dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView3"
android:layout_alignRight="#+id/imageView2"
android:text="Forget Password?"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
This will look like,
after 1st LinearLayout (root) you can write these lines:
<RelativeLayout
android:id="#+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top" >
<View
android:id="#+id/headerView"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:background="#drawable/Your-header-file-name" />
</RelativeLayout
Alternatively you may use LinearLayout instead of Relative. I used this one because it will not affect your LinearLayout. It's a good practice for beginners to use a weight for LinearLayout like:
<LinearLayout (root)
android:orientation="vertical"
android:weightSum ="2" >
<LineaLayout (child1)
android:layout_weight="1"/>
<LineaLayout (child2)
android:layout_weight="1"/>
</LinearLayout>
this will divide your layouts with weight 1. so you will get half screen for child 1 and remaining half for child 2

ScrollView on this layout is not working as i want it

i have a layout that contain several layouts and outside each layout there is an imageview so i wraped all the layouts under one called container and i want the container to be scrolled i tried several ways but its not what i want as a result.
A little bit of help would be appreciated thank you.
Here is my xml code:
enter code here
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/inner_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
android:gravity="center_horizontal" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="#drawable/header"
android:paddingLeft="2dip"
android:paddingRight="2dip" >
<Button
android:id="#+id/sample_button"
style="#android:style/Widget.Button.Small"
android:layout_width="35dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dip"
android:background="#drawable/burger" />
<TextView
android:id="#+id/actNAME"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="Tickets"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
android:textStyle="bold"
tools:ignore="HardcodedText" />
</RelativeLayout>
///i want here the scrollview over the container layout
<RelativeLayout
android:id="#+id/container"
android:layout_width="300dp"
android:layout_height="390dp"
android:layout_below="#+id/relativeLayout1"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:background="#8DAE79" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="14dp"
android:layout_marginTop="14dp"
android:background="#drawable/bg" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Ticket 1"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_alignLeft="#+id/imageTicketTwo"
android:layout_below="#+id/imageTicketTwo"
android:layout_marginTop="18dp"
android:background="#drawable/bg" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Ticket 3"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/imageTicketThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout3"
android:layout_alignParentRight="true"
android:layout_below="#+id/linearLayout3"
android:layout_marginTop="15dp"
android:background="#drawable/ticket_three" />
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_alignLeft="#+id/imageTicketThree"
android:layout_below="#+id/imageTicketThree"
android:layout_marginTop="17dp"
android:background="#drawable/bg" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Ticket 4"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/imageTicketFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout4"
android:layout_alignParentRight="true"
android:layout_below="#+id/linearLayout4"
android:layout_marginTop="15dp"
android:background="#drawable/ticket_four" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_alignLeft="#+id/imageTicketOne"
android:layout_below="#+id/imageTicketOne"
android:layout_marginTop="15dp"
android:background="#drawable/bg" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Ticket 2"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/imageTicketTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout2"
android:layout_alignParentRight="true"
android:layout_below="#+id/linearLayout2"
android:layout_marginTop="14dp"
android:background="#drawable/ticket_two" />
<ImageView
android:id="#+id/imageTicketOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearLayout1"
android:layout_marginLeft="10dp"
android:layout_marginTop="14dp"
android:background="#drawable/ticket_one" />
</RelativeLayout>
</RelativeLayout>
I managed to solve it b wrapping the container layout with a scrollView just by right click on the container select wrap container and choose Scrollview it will automatically wrap it with its specific attributes.

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/

Categories

Resources