Toolbar back button in Nested Navigation Graph - android-architecture-components

I am not sure if this is a duplicate or not but I could not find an answer to this.
This is my app structure and I am not too sure how to get proper toolbar support with it.
Activity A (NavHostFragment) -> Fragment A -> (Nested Navigation Graph) Fragment B -> Fragment BA
And the issue is when I go into by nested navigation graph and go to a fragment from inside there the toolbar no longer shows the Up button.
My Navigation Graph
<navigation 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/main_navigation"
app:startDestination="#id/loginFragment">
<fragment
android:id="#+id/loginFragment"
android:name="LoginFragment"
android:label="Login"
tools:layout="#layout/fragment_login">
<action
android:id="#+id/action_loginFragment_to_overviewFragment"
app:destination="#id/overview"
app:exitAnim="#anim/fragment_fade_exit"
app:popUpTo="#id/loginFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="#+id/overview"
android:name="OverviewFragment"
android:label="Overview"
tools:layout="#layout/fragment_overview" />
<fragment
android:id="#+id/accounts"
android:name="AccountsFragment"
android:label="Accounts"
tools:layout="#layout/fragment_accounts">
<action
android:id="#+id/openAccountDetails"
app:destination="#id/placeholder"
app:enterAnim="#anim/slide_in_right"
app:exitAnim="#anim/shrink"
app:popEnterAnim="#anim/grow"
app:popExitAnim="#anim/slide_out_right" />
</fragment>
<fragment
android:id="#+id/budget"
android:name="BudgetsFragment"
android:label="Budgets"
tools:layout="#layout/fragment_budgets" />
<fragment
android:id="#+id/insights"
android:name="InsightsFragment"
android:label="Insights"
tools:layout="#layout/fragment_insights" />
<!--Nested Navigation For Settings Scope-->
<navigation
android:id="#+id/settingsNavigation"
app:startDestination="#id/settingsFragment">
<fragment
android:id="#+id/settingsFragment"
android:name="SettingsFragment"
android:label="Settings"
tools:layout="#layout/fragment_settings">
<action
android:id="#+id/openSettingsBottomSheet"
app:destination="#+id/settingsBottomSheet" />
<action
android:id="#+id/openProfileFragment"
app:destination="#id/profileFragment"
app:enterAnim="#anim/slide_in_right"
app:exitAnim="#anim/shrink"
app:popEnterAnim="#anim/grow"
app:popExitAnim="#anim/slide_out_right" />
</fragment>
<dialog
android:id="#+id/settingsBottomSheet"
android:name="SettingsThemeBottomSheet" />
<fragment
android:id="#+id/profileFragment"
android:name="ProfileFragment"
android:label="Profile"
tools:layout="#layout/fragment_profile" />
</navigation>
<fragment
android:id="#+id/placeholder"
android:name="PlaceholderFragment"
android:label="Placeholder"
tools:layout="#layout/fragment_placeholder" />
</navigation>
If I pull the ProfileFragment outside into the main navigation then it works and I can get the toolbar to work but that is something I want to avoid and not do

Related

Android Navigation Component: How do I style toolbar based on navigation graph

I have the following nav_graph.xml:
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/nav_graph"
app:startDestination="#id/actualFragment">
<fragment
android:id="#+id/actualFragment"
android:name="com.online.view.ui.ActualFragment"
android:label="Актуальное"
tools:layout="#layout/fragment_actual" >
<action
android:id="#+id/action_actualFragment_to_actualEventFragment"
app:destination="#id/actualEventFragment"
app:enterAnim="#anim/nav_default_pop_enter_anim"
app:exitAnim="#anim/nav_default_pop_exit_anim" />
</fragment>
<fragment
android:id="#+id/actualEventFragment"
android:name="com.online.view.ui.detail.ActualEventFragment"
android:label="Актуальное"
tools:layout="#layout/actual_event_fragment" />
</navigation>
and I have MainActivity with the following layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:id="#+id/coordinatorLayout"
android:layout_width="match_parent" android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height"
android:background="#color/white"
android:paddingLeft="8dp"
app:contentInsetStart="8dp"
app:contentInsetStartWithNavigation="0dp"
app:titleTextAppearance="#style/TabTitles"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:theme="#style/ToolbarStyle"
/>
<fragment
android:id="#+id/content"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="#+id/bottom_tabs"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.587"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:navGraph="#navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_tabs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
app:labelVisibilityMode="labeled"
app:itemTextColor="#drawable/bottom_nav_colors"
app:itemTextAppearanceActive="#style/bottomBarTextSelected"
app:itemTextAppearanceInactive="#style/bottomBarText"
app:itemIconTint="#drawable/bottom_nav_colors"
android:alpha="1.0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/tabs_navigation"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Now I want to have different styling for activity toolbar when top level fragment is loaded and when its child is loaded (showing back arrow in toolbar).
QUESTION: How can I achieve this different styling for toolbar (appbar) if I use Android Navigation Component and I navigate from root fragment to child fragment using the following code:
Bundle bundle = new Bundle();
bundle.putString("id", ei.id);
MainActivity)context).getNavController().navigate(R.id.action_actualFragment_to_actualEventFragment, bundle);
NavigationUI uses an AppBarConfiguration object to manage the behavior of the Navigation button. The Navigation button’s behavior changes depending on whether the user is at a top-level destination. Have a look at their documentation Update UI components with NavigationUI

View becomes invisible when I add attach custom view background to the view

I am trying to add a custom background to a button to make two sides rounded. But when I attach or add custom view background, the button becomes invisible. Here is my xml code:
<android.support.constraint.ConstraintLayout
Have Some Code there
<Button
android:id="#+id/Top"
android:layout_width="30dp"
android:layout_height="34dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:drawableTop="#drawable/baseline_remove_24"
android:elevation="5dp"
android:paddingTop="5dp"
android:translationZ="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="#+id/mid_button"
android:layout_width="30dp"
android:layout_height="23dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:background="#drawable/button_mid"
android:text="2"
app:layout_constraintBottom_toBottomOf="#+id/bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/Top" />
<Button
android:id="#+id/bottom"
android:layout_width="30dp"
android:layout_height="34dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:background="#drawable/button_bottom_side"
//background added there
android:drawableBottom="#drawable/baseline_add_24"
android:elevation="5dp"
android:paddingBottom="5dp"
android:translationZ="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
Code for custom view from drawable folder is here:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:topLeftRadius="0dp"
android:topRightRadius="0dp"
android:bottomLeftRadius="50dp"
android:bottomRightRadius="50dp" />
<stroke android:width="1dp" android:color="#BABABA" />
<solid android:color="#ffffff"/>
padding android:left="20dp" android:top="20dp"
android:right="20dp" android:bottom="20dp" />
</shape>
Image is below:
(https://imghostr.com/BwBwqrc1)

Navigation View app:menu build gradle error

I am trying to use Navigation View in Drawer Layout, but I keep getting errors when building the file.
Here's what my xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/navigation_items"
/>
</android.support.v4.widget.DrawerLayout>
This leads to a build gradle error. My menu looks like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:id="#+id/menu_bookmark"
android:title="Bookmark" />
<item android:id="#+id/menu_save"
android:title="Save" />
<item android:id="#+id/menu_search"
android:title="Search" />
<item android:id="#+id/menu_share"
android:title="Share" />
</group>
</menu>
When I remove app:menu from the navigationView,the error goes away. What could be wrong?
My fix was that I needed to add app:headerLayout="#layout/my_header_layout" as well.

Data Binding Error Trying to Pass ViewModel into Include Layout with Abstract Variable Type

*EDIT: To answer my own question, I had to add EditorViewModel as an import to the parent abstract class in the outer layout, and cast the viewModel to the parent class using app:viewModel="#{((EditorViewModel)viewModel)}", that was it! I swear I don't recall doing this cast before though...*
My problem results because the included layout is defining a type which is the parent abstract class, and NOT the child concrete class, of the viewModel the outer layout is trying to share with the included layout.
I've confirmed that changing the included layout's type to the child concrete class' type fixes the issue, however, it should work with the abstract class type...
Here is how I define my viewModel variable, this is the concrete class in the type below:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="com.ootpapps.gpeofflinedatacollection.viewmodels.EquipmentEditorViewModel" />
</data>
...
A few statements later I include the layout, attempting to share the viewModel from above:
<include
layout="#layout/layout_spinner_location"
app:viewModel="#{viewModel}" />
Within the included layout the variable viewModel is defined as follows:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.ootpapps.gpeofflinedatacollection.viewmodels.EditorViewModel" />
</data>
And of course here's the EquipmentEditorViewModel showing it extends the abstract parent class EditorViewModel (defined as the parent class type above in the included layout):
public class EquipmentEditorViewModel extends EditorViewModel<Equipment> {
The error I receive is:
****/ data binding error ****msg:Cannot find the setter for attribute 'app:viewModel' with parameter type com.ootpapps.gpeofflinedatacollection.viewmodels.EquipmentEditorViewModel on com.ootpapps.gpeofflinedatacollection.databinding.LayoutSpinnerLocationBinding.
file:C:\Users\Ryan\AndroidstudioProjects\GPEOfflineDataCollection\app\src\main\res\layout\content_equipment_editor.xml
loc:31:33 - 31:41
****\ data binding error ****
As I mentioned above, changing the type in layout_spinner_location to "EquipmentEditorViewModel" fixes the error, HOWEVER, I need to use the abstract type in order to re-use this view as it doesn't always use an EquipmentEditorViewModel, sometimes it needs a "ToolEditorViewModel" or a "MeasurmentEditorViewModel" all of which extend EditorViewModel.
Thank you very much for your help. Maybe I will get lucky and George Mount will stop by.
Just for clarity if anyone comes across this.
Added 3 approaches to tackle the problem, #3 seems to be the winner
This seems to be an issue with the new gradle 3 and upward with the following error: Cannot find the setter for attribute 'app:viewModel'
Before
parent xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.PageWebViewViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.contentVisibility}"
app:baseUrl="#{null}"
app:builtInZoomControlsEnabled="#{false}"
app:cacheMode="#{viewModel.webViewCacheMode}"
app:data="#{viewModel.webViewData}"
app:domStorageEnabled="#{true}"
app:encoding="#{`UTF-8`}"
app:headers="#{viewModel.headers}"
app:javaScriptEnabled="#{true}"
app:loadUrl="#{viewModel.webViewUrl}"
app:mimeType="#{`text/html; charset=utf-8`}"
app:webChromeClient="#{viewModel.webChromeClient}"
app:webInterface="#{viewModel.webInterface}"
app:webInterfaceName="#{viewModel.webInterfaceName}"
app:webViewClient="#{viewModel.webViewClient}" />
<include
layout="#layout/request_error_view"
app:viewModel="#{viewModel}" />
<include
android:id="#+id/lyt_loading"
layout="#layout/loading_layout"
app:viewModel="#{viewModel}" />
</FrameLayout>
</layout>
include/child xml (layout/request_error_view)
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.BaseViewModel" />
</data>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/send_request_error_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="#{viewModel.errorVisibility}">
<TextView
android:id="#+id/text_error_sending_request"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/error_sending_request"
android:textColor="#color/window_primary_text"
android:textSize="#dimen/text_size_large" />
<Button
android:id="#+id/button_try_again"
style="#style/SuperbalistButton.Green.NoInset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/standard_content_margin"
android:onClick="#{viewModel::onClickReload}"
android:text="#string/try_again" />
</LinearLayout>
</layout>
After #1 (2nd variable approach, does not seem to work)
parent xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.PageWebViewViewModel" />
<variable
name="viewModelBase"
type="com.myapp.android.viewmodel.base.BaseViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.contentVisibility}"
app:baseUrl="#{null}"
app:builtInZoomControlsEnabled="#{false}"
app:cacheMode="#{viewModel.webViewCacheMode}"
app:data="#{viewModel.webViewData}"
app:domStorageEnabled="#{true}"
app:encoding="#{`UTF-8`}"
app:headers="#{viewModel.headers}"
app:javaScriptEnabled="#{true}"
app:loadUrl="#{viewModel.webViewUrl}"
app:mimeType="#{`text/html; charset=utf-8`}"
app:webChromeClient="#{viewModel.webChromeClient}"
app:webInterface="#{viewModel.webInterface}"
app:webInterfaceName="#{viewModel.webInterfaceName}"
app:webViewClient="#{viewModel.webViewClient}" />
<include
layout="#layout/request_error_view"
app:viewModel="#{viewModelBase}" />
<include
android:id="#+id/lyt_loading"
layout="#layout/loading_layout"
app:viewModel="#{viewModelBase}" />
</FrameLayout>
</layout>
After #2 (casting approach, works)
parent xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.PageWebViewViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.contentVisibility}"
app:baseUrl="#{null}"
app:builtInZoomControlsEnabled="#{false}"
app:cacheMode="#{viewModel.webViewCacheMode}"
app:data="#{viewModel.webViewData}"
app:domStorageEnabled="#{true}"
app:encoding="#{`UTF-8`}"
app:headers="#{viewModel.headers}"
app:javaScriptEnabled="#{true}"
app:loadUrl="#{viewModel.webViewUrl}"
app:mimeType="#{`text/html; charset=utf-8`}"
app:webChromeClient="#{viewModel.webChromeClient}"
app:webInterface="#{viewModel.webInterface}"
app:webInterfaceName="#{viewModel.webInterfaceName}"
app:webViewClient="#{viewModel.webViewClient}" />
<include
layout="#layout/request_error_view"
app:viewModel="#{((com.myapp.android.viewmodel.base.BaseViewModel) viewModel)}" />
<include
android:id="#+id/lyt_loading"
layout="#layout/loading_layout"
app:viewModel="#{((com.myapp.android.viewmodel.base.BaseViewModel) viewModel)}" />
</FrameLayout>
</layout>
After #3 (import and cast approach, works)
parent xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="com.myapp.android.viewmodel.base.BaseViewModel" />
<variable
name="viewModel"
type="com.myapp.android.viewmodel.base.PageWebViewViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<WebView
android:id="#+id/webview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="#{viewModel.contentVisibility}"
app:baseUrl="#{null}"
app:builtInZoomControlsEnabled="#{false}"
app:cacheMode="#{viewModel.webViewCacheMode}"
app:data="#{viewModel.webViewData}"
app:domStorageEnabled="#{true}"
app:encoding="#{`UTF-8`}"
app:headers="#{viewModel.headers}"
app:javaScriptEnabled="#{true}"
app:loadUrl="#{viewModel.webViewUrl}"
app:mimeType="#{`text/html; charset=utf-8`}"
app:webChromeClient="#{viewModel.webChromeClient}"
app:webInterface="#{viewModel.webInterface}"
app:webInterfaceName="#{viewModel.webInterfaceName}"
app:webViewClient="#{viewModel.webViewClient}" />
<include
layout="#layout/request_error_view"
app:viewModel="#{(BaseViewModel) viewModel)}" />
<include
android:id="#+id/lyt_loading"
layout="#layout/loading_layout"
app:viewModel="#{((BaseViewModel) viewModel)}" />
</FrameLayout>
</layout>
This method works perfectly
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewmodel"
type="com.myapp.data.ViewModel" />
</data>
<include
android:id="#+id/include"
layout="#layout/buttons_layout" />
</layout>
buttons_layout
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewmodel"
type="com.myapp.data.ViewModel" />
</data>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="#{() -> viewmodel.onClickChangeName()}"
android:text="Change Name"
app:layout_constraintTop_toBottomOf="#id/include"
app:layout_constraintStart_toStartOf="parent"
/>
</layout>
MainActivity
lateinit var dataBinding: ActivityMainBinding
lateinit var viewModel: viewModel
dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)
viewModel = ViewModelProvider(this).get(ViewModel::class.java)
dataBinding.include.viewModel = viewModel
dataBinding.viewModel = viewModel
dataBinding.executePendingBindings()

How do I stretch a Xamarin GridLayout's contents to fill the screen?

I'm using a GridLayout in Xamarin to create a Calculator app and am having trouble getting it to fill the screen. One possible solution I found was to use a LinearLayout for each row of the controls. The problem with this is that my = button spans two rows and I wasn't able to use it. I have also tried changing the GridLayout's layout_width and layout_height with no luck. What other options do I have? Here's my code and some screenshots:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:columnCount="4"
android:orientation="horizontal">
<TextView
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="4"
android:gravity="right"
android:layout_gravity="fill"
android:id="#+id/resultView" />
<Button
android:text="Del"
android:id="#+id/button1" />
<Button
android:text="C"
android:id="#+id/button1" />
... <!-- Buttons continue -->
<Button
android:text="3"
android:id="#+id/button1" />
<Button
android:text="="
android:layout_gravity="fill"
android:layout_rowSpan="2"
android:id="#+id/button1" />
<Button
android:text="0"
android:layout_columnSpan="2"
android:layout_gravity="fill"
android:id="#+id/button1" />
<Button
android:text="."
android:id="#+id/button1" />
</GridLayout>
</LinearLayout>
What I have:
What I want:
Edit: I know each button has the same id, but I'm only concerned with getting the layout right at the moment.

Resources