Hi I am trying to display a button on top of google maps, could someone please tell me how I could acheive this please as I have tried different positions and my button displays behind the map.
This is my code so far:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/BlanchedAlmond" >
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:onClick="startActivity"
android:text="#string/start_activity"
android:layout_alignParentBottom="true" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/startActivityButton"
/>
</RelativeLayout>
If you are giving a try to an alternate solution by doing it in java file you can try the code below in onCreate method ,this will create a button on top of google map
Button button = new Button(this);
button.setText("Click me");
addContentView(button, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(this,SecondActivity.class);
startActivity(i);
}
});
Use this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/BlanchedAlmond"
android:orientation="vertical" >
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:onClick="startActivity"
android:text="#string/start_activity" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/startActivityButton"
/>
</RelativeLayout>
If you're using a RelativeLayout it's important that your layers has the same order as your components
So if you want a button to be on top of your map you need FIRST place the map, and THEN a button.
correct:
<RelativeLayout>
<fragment android:id="#+id/map"/>
<Button .../>
</RelativeLayout>
incorrect:
<RelativeLayout>
<Button .../>
<fragment android:id="#+id/map"/>
</RelativeLayout>
try this it may help you, to keep as header
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/BlanchedAlmond"
android:orientation="vertical" >
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:onClick="startActivity"
android:text="#string/start_activity" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
to Overlay button on Map use this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/BlanchedAlmond" >
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal|center_vertical"
android:onClick="startActivity"
android:text="#string/start_activity" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_above="#+id/startActivityButton"
android:layout_height="wrap_content" />
</RelativeLayout>
use this..
<?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" >
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/map"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal|center_vertical"
android:onClick="startActivity"
android:text="start_activity" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/startActivityButton" />
Have you tried FrameLayout?
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/BlanchedAlmond" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/startActivityButton"
/>
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:onClick="startActivity"
android:text="#string/start_activity"
android:layout_alignParentBottom="true" />
</FrameLayout >
What I do in my app is to add a fragment dynamically on top when the map is shown.
Code and layout as requested by MD:
Main XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/details"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Turios" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/display_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.PagerTitleStrip
android:id="#+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#333"
android:paddingBottom="4dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="4dp"
android:textColor="#fff" >
</android.support.v4.view.PagerTitleStrip>
</android.support.v4.view.ViewPager>
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:background="#drawable/shape_background_darkgrey"
android:padding="5dp" />
</FrameLayout>
Mapoptions XML (I just add buttons dynamically to the LinearLayout):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:orientation="vertical"
android:paddingTop="65dp"
android:paddingRight="10dp" >
<LinearLayout
android:id="#+id/map_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
And the code:
private FragmentTransaction addMapFragment(FragmentTransaction ft) {
if (mapsFragment == null) {
AddressHolder address = (device.isMultiPane()) ? null
: getSelectedAddressHolder();
mapsFragment = GoogleMapFragment.newInstance(address);
ft.add(R.id.details, mapsFragment, Turios.FRAGMENT_MAP_TAG);
mapsOptionsFragment = new GoogleMapOptionsFragment();
ft.add(R.id.details, mapsOptionsFragment, FRAGMENT_MAP_OPTIONS_TAG);
} else {
ft.attach(mapsFragment);
ft.attach(mapsOptionsFragment);
}
return ft;
}
#Override public void onTabSelected(Tab tab,
android.app.FragmentTransaction ft) {
int position = tab.getPosition();
FragmentTransaction t = fm.beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
if (position == DisplayFragment.NAVIGATION_INDEX) {
if (!device.isMultiPane() && mapsFragment != null
&& mapsOptionsFragment != null) {
t.detach(mapsFragment);
t.detach(mapsOptionsFragment);
}
if (browserFragment != null) {
t.detach(browserFragment);
}
}
if (position == GoogleMapFragment.NAVIGATION_INDEX) {
t = addMapFragment(t);
}
if (position == BrowserFragment.NAVIGATION_INDEX) {
if (browserFragment == null) {
browserFragment = new BrowserFragment();
t.add(R.id.details, browserFragment,
Turios.FRAGMENT_BROWSER_TAG);
} else {
t.attach(browserFragment);
}
}
t.commit();
}
#Override public void onTabUnselected(Tab tab,
android.app.FragmentTransaction ft) {
int position = tab.getPosition();
FragmentTransaction t = fm.beginTransaction();
if (position == GoogleMapFragment.NAVIGATION_INDEX) {
t.detach(mapsFragment);
t.detach(mapsOptionsFragment);
}
if (position == BrowserFragment.NAVIGATION_INDEX) {
t.detach(browserFragment);
}
t.commit();
}
do this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/BlanchedAlmond"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:onClick="startActivity"
android:text="#string/start_activity" />
</LinearLayout>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/startActivityButton"
/>
</RelativeLayout>
Related
I am using sliding panel layout and in that i have ONE floating buttons.Now when i Click on the button the view Slides first and then i have to click again on button to perform action.
I want to perform action on only single click without the sliding movement of parent view.
Look at these images
Look at 1 images
look at this
Here is my
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="#+id/Sliding"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="match_parent"
android:id="#+id/leftSide"
android:background="#ef3"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contact"
android:background="#drawable/bg_key"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:background="#color/colorAccent"
android:id="#+id/rightSide"
android:layout_marginLeft="170dp"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:focusable="false"
app:srcCompat="#drawable/ic_menu_camera"
android:id="#+id/call"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/message" />
</RelativeLayout>
</android.support.v4.widget.SlidingPaneLayout>
here is my java code
SlidingPaneLayout sp;
#Override
protected void onCreate(Bundle savedInstanceState)
{
context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
call = (FloatingActionButton) findViewById(R.id.call);
sp = (SlidingPaneLayout) findViewById(R.id.Sliding);
assert sp != null;
sp.setPanelSlideListener(this);
sp.setSliderFadeColor(Color.TRANSPARENT);
sp.openPane();
mList = new ArrayList<Contacts>();
call.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Log.e("CALL","CALL");
try
{
if(number.isEmpty())
{
Toast.makeText(context,"Please select contact first",Toast.LENGTH_SHORT).show();
}
else
{
calling();
number=null;
}
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(context,"This is not the valid contact",Toast.LENGTH_SHORT).show();
}
}
});
}
Use this code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v4.widget.SlidingPaneLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="#+id/Sliding"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="300dp"
android:layout_height="match_parent"
android:id="#+id/leftSide"
android:background="#ef3"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contact"
android:background="#drawable/bg_key"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v4.widget.SlidingPaneLayout>
<RelativeLayout
android:layout_width="match_parent"
android:background="#color/colorAccent"
android:id="#+id/rightSide"
android:layout_marginLeft="170dp"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:focusable="false"
app:srcCompat="#drawable/ic_menu_camera"
android:id="#+id/call"
android:layout_alignParentTop="true" />
</RelativeLayout>
</RelativeLayout>
I just started to use fragments but I have problems to use them correctly.
This is my case. I'm using this BottomBar with some items, when user clicks on items fragments change. That's ok, but I can't set a match_parent on the second card's height. I'd like to use all the remaining space.
This is the result:
This is code in my CDetails.java where I use the BottomBar and the FragmentManager:
// BottomBar
mBottomBar = BottomBar.attach(CustomersDetails.this, savedInstanceState);
//mBottomBar.hideShadow();
mBottomBar.noNavBarGoodness();
mBottomBar.noResizeGoodness();
//mBottomBar.noScalingGoodness();
mBottomBar.noTabletGoodness();
//mBottomBar.useFixedMode();
mBottomBar.setItems(R.menu.bottom_navigation_customers);
mBottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() {
#Override
public void onMenuTabSelected(#IdRes int menuItemId) {
if (menuItemId == R.id.bottomBarCustomerNotes) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
CustomersFragmentsNotes notes = new CustomersFragmentsNotes();
fragmentTransaction.replace(R.id.fragment_container, notes);
fragmentTransaction.commit();
}
if (menuItemId == R.id.bottomBarCustomerTickets) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
CustomersFragmentsTickets tcks = new CustomersFragmentsTickets();
fragmentTransaction.replace(R.id.fragment_container, tcks);
fragmentTransaction.commit();
}
if (menuItemId == R.id.bottomBarCustomerContracts) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
CustomersFragmentContracts cntrs = new CustomersFragmentContracts();
fragmentTransaction.replace(R.id.fragment_container, cntrs);
fragmentTransaction.commit();
}
if (menuItemId == R.id.bottomBarCustomerContacts) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
CustomersFragmentContacts cnts = new CustomersFragmentContacts();;
fragmentTransaction.replace(R.id.fragment_container, cnts);
fragmentTransaction.commit();
}
}
#Override
public void onMenuTabReSelected(#IdRes int menuItemId) {
}
});
//Setting colors
mBottomBar.mapColorForTab(0, "#F44336");
mBottomBar.mapColorForTab(1, "#7E57C2");
mBottomBar.mapColorForTab(2, "#5C6BC0");
mBottomBar.mapColorForTab(3, "#42A5F5");
This is my activity_cdetails.xml (the container):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/left_drawer_activity_cdetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/right_drawer_activity_cdetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/sfondo_sfumato"
>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:id="#+id/appbar_activity_cdetails">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_activity_cdetails"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="55dp"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
card_view:cardCornerRadius="5dp"
card_view:cardBackgroundColor="#FFFFFF"
card_view:cardElevation="7dp"
>
<!--<ScrollView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent">-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:weightSum="1"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/title_cdetails"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="Title"
android:textSize="22sp"
android:typeface="serif"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:textSize="18sp"
android:layout_below="#id/title_cdetails"
android:id="#+id/cdetails_nome"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_below="#id/cdetails_nome"
android:text="New Text"
android:textSize="18sp"
android:id="#+id/cdetails_città "
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_below="#id/cdetails_città "
android:textSize="18sp"
android:id="#+id/cdetails_indirizzo"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_below="#id/cdetails_indirizzo"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:textSize="18sp"
android:id="#+id/cdetails_provincia"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_below="#id/cdetails_provincia"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:textSize="18sp"
android:id="#+id/cdetails_phone"
android:autoLink="phone"
/>
</RelativeLayout>
<!--</ScrollView>-->
</android.support.v7.widget.CardView>
<!-- Fragment Container -->
<LinearLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view_right_activity_cdetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_right_c"
app:menu="#menu/menu_right_c" />
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view_left_activity_cdetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/menu_left_drawer" />
</android.support.v4.widget.DrawerLayout>
And this is activity_c_fragment_notes.xml (first fragment):
<?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.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
card_view:cardCornerRadius="5dp"
card_view:cardBackgroundColor="#B2EBF2"
card_view:cardElevation="7dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="This is Notes"
/>
</android.support.v7.widget.CardView>
</LinearLayout>
Could anyone please tell me where I'm wrong?
Thanks in advance.
Edit
RRR solution works only on the default selected item, the first fragment. If I change item in the BottomBar second card's layout is the same as the pic I posted. Any other ideas?
use android:fillViewport=true for your ScrollView inside CoordinatorLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
fillViewPort defines whether the scrollview should stretch its content
to fill the viewport.
source
i want to implement Globe-Weis File Folder like picture below which by clicking on green button it scrolling smoothly up and by clicking on the green button again ,the folder page scrolling down smoothly.
what i try so far was putting three scrollView in a frameLayout , and to open and close it
if (!underIsOpen) {
ObjectAnimator
.ofInt(sv_Under, "scrollY",
findViewById(R.id.ll_under_botton).getTop())
.setDuration(1000).start();
underIsOpen = true;
} else {
ObjectAnimator
.ofInt(sv_Under, "scrollY",
findViewById(R.id.ll_under_s_part).getTop())
.setDuration(1000).start();
underIsOpen = false;
}
but it just work on the scrollView which is on top
my code is:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test3);
ll_under_s_part = (LinearLayout) findViewById(R.id.ll_under_s_part);
sv_Under = (ScrollView) findViewById(R.id.scrollView1);
sv_Mid = (ScrollView) findViewById(R.id.scrollView2);
sv_Top = (ScrollView) findViewById(R.id.scrollView3);
}
public void onClick_under_left(View v) {
Toast.makeText(getApplicationContext(), "under layout",
Toast.LENGTH_SHORT).show();
if (!underIsOpen) {
ObjectAnimator
.ofInt(sv_Under, "scrollY",
findViewById(R.id.ll_under_botton).getTop())
.setDuration(1000).start();
underIsOpen = true;
} else {
ObjectAnimator
.ofInt(sv_Under, "scrollY",
findViewById(R.id.ll_under_s_part).getTop())
.setDuration(1000).start();
underIsOpen = false;
}
}
public void onClick_mid_left(View v) {
Toast.makeText(getApplicationContext(), "mid layout",
Toast.LENGTH_SHORT).show();
}
public void onClick_top_left(View v) {
Toast.makeText(getApplicationContext(), "top layout",
Toast.LENGTH_SHORT).show();
if (!topIsOpen) {
ObjectAnimator
.ofInt(sv_Top, "scrollY",
findViewById(R.id.ll_top_botton).getTop())
.setDuration(1000).start();
topIsOpen = true;
} else {
ObjectAnimator
.ofInt(sv_Top, "scrollY",
findViewById(R.id.ll_top_s_part).getTop())
.setDuration(1000).start();
topIsOpen = false;
}
}
xml:
<?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="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll_under_s_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#ccff00"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/ll_under_botton"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#519B57"
android:onClick="onClick_under_left"
android:orientation="vertical"
android:text="B T N" />
<LinearLayout
android:id="#+id/ll_under_p_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#edf5ee"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_under_1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_under_2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1000dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll_mid_s_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#00000000"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_mid_3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/ll_mid_botton"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#088da5"
android:onClick="onClick_mid_left"
android:orientation="vertical"
android:text="B T N" />
<LinearLayout
android:id="#+id/ll_mid_p_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#e6f3f6"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_mid_1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
<ScrollView
android:id="#+id/scrollView3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll_top_s_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#00000000"
android:orientation="vertical"
android:visibility="visible" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_top_3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/ll_top_2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/ll_top_botton"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#D11141"
android:onClick="onClick_top_left"
android:orientation="vertical"
android:text="B T N" />
<LinearLayout
android:id="#+id/ll_top_p_part"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#fae7ec"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>
the second way i tried was using animation but no success to result i am looking for :
public void SlideUP(View view, Context context) {
view.startAnimation(AnimationUtils.loadAnimation(context,
R.anim.slid_up));
}
public void SlideDown(View view, Context context) {
view.startAnimation(AnimationUtils.loadAnimation(context,
R.anim.slid_down));
}
any other way that i can implement this?
I don't think adding so may layout on a single screen with scrollbars is a good idea, you can apply simple frame layouts and list them accordingly and when clicking on any of the desired folder icons just animate it towards top, and it will also show the content of the folder.
https://github.com/kikoso/Swipeable-Cards
you could customize this library to do that, I have done a similar kind of app and applied the same library with my custom changes.
With the layout below the buttons are being shown on top of the page. How can I make them appear below, after the container, down on the page?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/container"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/Main"
android:onClick="ClickHomePage"
android:text= "#string/Home"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/map"
android:onClick="ClickClients"
android:text= "#string/Clients"
>
</Button>
</LinearLayout>
</LinearLayout>
The MainActivity looks as follows and the HomePage.xml is also below
public class MainActivity extends ActionBarActivity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GetButtonClicked(5);
setContentView(R.layout.activity_main);
}
public void GetButtonClicked(int position)
{
// update the main content by replacing fragments
Fragment fragment = null;
switch (position){
case 0:
fragment= new FirstPageFragment();
break;
default:
fragment = new FirstPageFragment();
break;
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
public void ClickHomePage(View view){
GetButtonClicked(0);
}
public void ClickClients(View view){
GetButtonClicked();
}
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="com.test.FirstPageFragment" android:background="#drawable/theme">
</FrameLayout>
This is the FirstPage
public class FirstPageFragment extends Fragment {
public FirstPageFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first_page, container, false);
}
}
Use ralative layout insted of linear.
Make a different layout for bottom buttons, and then at the last of your container layout use this:
<include android:id="#+id/bottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
layout="#layout/bottom_buttons"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="#+id/Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickHomePage"
android:text="#string/Home" />
<Button
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickClients"
android:text="#string/Clients" >
</Button>
</LinearLayout>
Try this
Use RelativeLayout with android:layout_alignParentBottom="true" step by step guide is available here.
Your skeleton for layout should look like this
<RelativeLayout
<LinearLayout android:layout_alignParentBottom="true">
<Button
<Button
</LinearLayout>
</RelativeLayout>
Final Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/Main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickHomePage"
android:text="Home" />
<Button
android:layout_marginLeft="30dp"
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="ClickClients"
android:text="Clients" >
</Button>
</LinearLayout>
The issue was that I did not include the container in another layout...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.MainPageActivityActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="#+id/container">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_alignParentTop="#+id/container">
and insert buttons layout here....
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/Main"
android:onClick="ClickHomePage"
android:text= "#string/Home"
/>
I have layout file custom_lock.xml. It has 3 child layouts. Problem is when I try to access the elements of the layout from MainActivity.java, it returns null. Its driving me nuts. Please help me. Thanks.
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:name="#+id/place1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:gravity="center"
android:text="Place"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:name="#+id/listofapps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/holo_blue_light"
android:text="List of Apps" />
<ListView
android:name="#+id/sites"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/holo_green_light" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:name="#+id/calories"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/holo_purple"
android:text="Health Data" />
<ListView
android:name="#+id/dialer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/darker_gray" />
</LinearLayout>
</LinearLayout>
Following is my MainActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_lock);
startService(new Intent(this, MyService.class));
TextView placexml = (TextView) findViewById(R.id.place1);
if (placexml == null)
System.out.println("placexml");
String place = "work";
//System.out.println("place: "+place);
placexml.setText(place);
boolean isApiRunning = ContextSdk
.isSemusiSensing(getApplicationContext());
if (isApiRunning)
Api.stopContext();
else {
SdkConfig config = new SdkConfig();
config.setPlacesAccuracyLevel(PlacesAccuracyLevel.EAccuracyHigh);
config.setActivityAccuracyLevel(ActivityAccuracyLevel.EAccuracyHigh);
config.setActivityTrackingAllowedState(true);
config.setAnalyticsTrackingAllowedState(true);
config.setDemographicsTrackingAllowedState(true);
config.setPedometerTrackingStateAllowed(true);
config.setPlacesTrackingAllowedState(true);
config.setRuleEngineEventStateAllowed(true);
Api.startContext(getApplicationContext(), config);
}
// reloadRssHandler.postDelayed(relaodRssRunnable, time);
//updateUILayer();
/*
txt1.setOnClickListener(new OnClickListener() {
#Override public void onClick(View arg0) { // TODO Auto-generated
method stub System.out.println("finishing......."); finish();
}
});
*/
}
When I run this program, "placexml" gets printed on console. I don't know, why this is happening. place1 is returning null from xml. Please help.
Change lines
android:name="#+id/place1"
to
android:id="#+id/place1"
You need to set ID instead of name.
setContentView(R.layout.custom_lock);
Wrong name of your layout "custom_layout"?
Try changing
<TextView
android:name="#+id/place1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:gravity="center"
android:text="Place"
android:textColor="#000000" />
with
<TextView
android:id="#+id/place1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:gravity="center"
android:text="Place"
android:textColor="#000000" />