Change Background Color of MvxItemTemplate? - xamarin

How does one change the Background Color of an MvxItemTemplate?
I can change the Background of the MvxListView, but that changes the background of all the elements.
Here's the relevant code:
<MvvmCross.Binding.Droid.Views.MvxListView
android:id="#+id/favoritesList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxItemTemplate="#layout/template_screen"
local:MvxBind="ItemsSource FavoritesGroupedList; ItemClick ScreenSelectedCommand; ItemLongClick ShowUnFavoriteCommand" />
If I place BackgroundColor BlackOrBlueColor(IsUnFavorite) in the local:MvxBind for the ListView, it works. I tried to place the Binding in my template:
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/screenIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
local:MvxBind="BackgroundColor BlackOrBlueColor(IsUnFavorite)"/>
<TextView
android:id="#+id/screenText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" />
</LinearLayout>
But it doesn't work.

You can't change the MvxItemTemplate background color, but you can change the background color of the root layout inside the item template:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="BackgroundColor BlackOrBlueColor(IsUnFavorite)">

Related

How do i make the buttons from the following code be all the same size and occupy the entire gridLayout?

I have this grid layout which is part of an another grid layout, and contains 6 buttons.
It is next to a relative grid layout, if that makes any difference, thats why its width and height are set at 0dp.
How do I make them all the same size and make them fill the grid without using fixed values?
<android.support.v7.widget.GridLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.5"
app:layout_columnWeight="1"
app:layout_rowWeight="1"
app:columnCount="2"
app:rowCount="3"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:text="#string/pocetna_dugme_prijava_problema"
style="#style/StartMenuButton"
android:background="#drawable/rounded_corners_button_start_menu"
android:id="#+id/btnPrijavaProblemaLink"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pocetna_dugme_prijava_ebill"
style="#style/StartMenuButton"
android:background="#drawable/rounded_corners_button_start_menu"
android:id="#+id/btnPrijavaEracunLink"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pocetna_dugme_prijava_ukljucenje"
style="#style/StartMenuButton"
android:background="#drawable/rounded_corners_button_start_menu"
android:id="#+id/btnUkljucenjeLink"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pocetna_dugme_prepaid_dopuna"
android:padding="0dp"
android:drawableBottom="#drawable/prepaid10"
style="#style/StartMenuButton"
android:background="#drawable/rounded_corners_button_start_menu"
android:id="#+id/btnPrepaidDopunaLink"/>
If you want the control to divide the screen space horizontally and vertically,you can use LinearLayout to achieve this, and set the android:layout_weight="1" property for the controls.
And to make the UI look better, you can also set android:layout_margin property.
You can refer to the following code:
<?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:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:text="button1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:text="button2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:text="button3"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_margin="5dp"
android:layout_weight="1"
android:text="button4"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
You should change all your nested LinearLayouts to use ConstraintLayouts. Nested LinearLayouts inflate slowly, which was why ConstraintLayouts were created to replace them about 4-5 years ago. Android.Support.V7.Widgets were also dropped in favour of AndroidX controls at about the same time.

How to add Scroll View to a Linear Layout which is having Linear layouts again inside it

I have a Linear layout and again inside the linear layout I have some list off apps which are designed using Linear layouts, Now I want to scroll this list of Linear layouts. Please help me how to achieve this.
If you want to add scroll view in LinearLayout, but there are many LinearLayouts in LinearLayout, scroll this list of layout, you can take a look:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="fill_parent"
android:layout_height="fill_parent">
<ScrollView android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- Content here -->
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- Content here -->
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- Content here -->
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<!-- Content here -->
</LinearLayout>
</LinearLayout>
</ScrollView>

Xamarin Tabhost - overlapped tab content

I created a tabbed application using TabHost widget, from Xamarin.
When I am changing the tabs, they are overlapping.
https://imgur.com/a/cfRWlsl
This is the layout for the main page.
I have the tabs at the buttom of the screen and the content of the tabs above.
The tabs are created dynamically.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#+id/actualtabcontent"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="#+id/tabContainer"/>
<LinearLayout android:id="#+id/tabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TabHost android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/fullOpacityBlack">
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<TabWidget android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="90dp"
android:layout_weight="0"
android:layout_alignParentBottom="true"
android:background="#color/fullOpacityBlack" />
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
</RelativeLayout>

Xamarin Designer throws exception

I'm working on a current project using Xamarin.Android. I got several view sthat use the same layout. I got used to define everything in a style for this while working with Android Studio. The problem is that Xamarin's Designer doesn't accept that "layout_width" and "layout_height" are defined in a style.
Of course it is a possibility to define those with the views, but it would increase the lines of XML-code quite a bit, and also I'd have to change more than one view if I'd change something.
I already looked into the topic but didn't find a workaround. Maybe someone got a similar problem and might have found a proper solution.
Fragment_Therapist.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:weightSum="7">
<RelativeLayout
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="#android:drawable/ic_menu_gallery"
android:layout_width="250dp"
android:layout_height="250dp"
android:id="#+id/profile_icon"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true" />
<!-- Profile Name -->
<RelativeLayout
android:id="#+id/sublayout_I"
android:layout_marginTop="25dp"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#id/profile_icon">
<TextView
android:id="#+id/profile"
android:text="#string/therapistfragment_profile"
android:textColor="#000000"
android:textStyle="bold"
android:minWidth="50dp"
android:textSize="25dp" />
<TextView
android:id="#+id/profile_name"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<!-- Profile Description-->
<RelativeLayout
android:id="#+id/sublayout_II"
android:layout_marginTop="25dp"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#id/sublayout_I">
<TextView
android:id="#+id/description"
android:textColor="#000000"
android:textStyle="bold"
android:minWidth="50dp"
android:text="#string/therapistfragment_description"
android:textSize="25dp" />
<TextView
android:id="#+id/profile_description"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
<!-- Edit, Info, Delete, Cancel and Save-->
<LinearLayout
android:layout_weight="5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:weightSum="2">
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1">
<Button
android:id="#+id/edit"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1">
<Button
android:id="#+id/info"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
android:weightSum="4">
<LinearLayout
android:id="#+id/left"
style="#style/PlaceHolder" />
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="2">
<Button
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="15dp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/right"
style="#style/PlaceHolder" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="PlaceHolder">
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_weight">1</item>
</style>
</resources>

CoordinatorLayout scroll Tablayout itself

I want to have an activity, which contains a TabLayout and a Viewpager and some stuff below the Viewpager, which is visible in every Tab, and also scrollable.
When the recyclerview "tracks_recyclerview" is scrolled up, the TabLayout and the Edittext and the Viewpager hide as they should and the "all_tracks"-relativelayout and the horizontal Recyclerview stay at the top.
Here is what i want:
The content above the recyclerview should also be scrollable itself. So for now it is only possible to scroll down the "tracks_recyclerview". but the other parts of the view should also scroll down the list.
My Code looks something like this:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/content_activity"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/transparent">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
app:tabContentStart="2dp"
app:tabGravity="fill"
app:tabIndicatorHeight="2dp"
app:tabMinWidth="24dp"
app:tabMode="fixed"
app:tabPadding="1dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeight"
android:layout_margin="10dp"
app:layout_scrollFlags="scroll|enterAlways" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#444"
app:layout_scrollFlags="scroll|enterAlways"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/all_tracks"
android:layout_width="140dp"
android:layout_height="155dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp">
<ImageView
android:id="#+id/cover"
android:layout_width="140dp"
android:layout_height="120dp"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:scaleType="fitCenter"
android:src="#drawable/abc_btn_rating_star_on_mtrl_alpha" />
<TextView
android:id="#+id/name"
android:layout_width="140dp"
android:layout_height="35dp"
android:layout_below="#+id/cover"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="12sp" />
</RelativeLayout>
<?-- horizontal Recyclerview -->
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="155dp"
android:layout_marginBottom="10dp"
android:layout_toRightOf="#+id/all_tracks" />
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/tracks_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
I Hope you could understand my problem and maybe help me out.
Thanks,
Thomas
Edit: Is there somebody who can help me?

Resources