Upgrading from Android Wear 2.0.0-alpha3 to 2.0.0 release breaks my layouts - wear-os

After upgrading from 2.0.0-alpha3 to 2.0.0, most of my views looked skewed. This is the XML of the layout I am using:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="oviroa.bestshot.android.StartPlayActivity"
tools:deviceIds="wear"
android:padding="15dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
app:layout_box="all">
<TextView
android:id="#+id/shot_type"
app:layout_box="all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/forehand"
android:theme="#style/BST.HeaderText"/>
<Button
android:layout_marginTop="30dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:id="#+id/record"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/swoosh_background"
android:text="#string/record_action"
android:gravity="center_horizontal|bottom"
android:textAlignment="center"
android:paddingBottom="15dp"
android:theme="#style/BST.ButtonWithIcon.Bold" />
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
The button is considerably skewed as you can see in the screenshots below. Iam not doing any manipulations via code.
This is with 2.0.0-alpha3:
And this is with 2.0.0, the final release:
I am testing on LG Urbane 2nd gen LTE.

This was actually a bug fix in BoxInsetLayout - before, the android:padding="5dp" on your FrameLayout was being ignored (that's why the 'Forehand' was directly on the edge of the app:layout_box="all" edge). Now, it is being respected and your entire inner view is being padded in on all sides, leading to less space overall.
Removing the android:padding="5dp" in your FrameLayout should be enough to restore the previous look.

Related

Show BottomNavigationView when stop scrolling

I use attribute app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior" to hide BottomNavigationView when I'm scrolling down. It works. When I scroll up, BNV is showed again. Also works. But when I finished scrolling down (BNV is hidden) I want to see BNV without scrolling up. Is it possible?
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2AB670"
tools:context=".presentation.MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/bottom_navigation_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/app_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green_01"
app:itemBackground="#drawable/bottom_navigation_selector"
app:itemIconTint="#color/white"
app:itemTextAppearanceActive="#style/ItemTextAppearanceActive"
app:itemTextColor="#color/white"
app:labelVisibilityMode="labeled"
app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior"
android:layout_gravity="bottom"
app:menu="#menu/bottom_navigation_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Why can't I interact with any views within my fragments?

^.^
I'm very new to xamarin.android and xamarin in general, and I'm finding the layout handling so much more trouble than I expected! I've finally managed to get fragments switching in and out in order to display different pages in my app, but now that that's working, the views/controls/elements such as buttons, scrollable layouts, text input, etc are not accepting input!
By that, I mean when testing, buttons do not recognise me tapping on them, my once-scrollable listview no longer scrolls when I swipe, etc.
This only applies to the views within the fragments, as the navigation drawer and other persistent default app buttons are all still fine.
I've looked for solutions everywhere but can't find anything that helps!
I'd greatly appreciate any advice/assistance, and if you require any additional information please just ask! ^.^
Thanks so much in advance! ^.^ <3
Code:
activity_main.xml:
<androidx.drawerlayout.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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#android:color/white"
android:id="#id/MainLayout"
android:paddingTop="50dp">
</LinearLayout>
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
One of my fragment layouts (content_main.xml):
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/app_bar_main"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:id="#+id/ClothesList_ListView"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"
android:choiceMode="singleChoice"
android:scrollbarSize="40px"/>
</RelativeLayout>

Dynamically load xml control and share UI control

I am new to xamarin. Is it possible to load a shared UI control in an xml file, if yes, how? I am open to better idea.
Below is a static loading via include, where parent.axml statically load child.xml.
<include
android:id="#+id/child"
layout="#layout/child"
android:layout_below="#id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
parent.axml
<?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">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include
android:id="#+id/child"
layout="#layout/child"
android:layout_below="#id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/parent_layout"
android:layout_below="#id/child">
<TextView
android:id="#+id/parent_text"
android:layout_margin="16dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to go to the moon!"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true" />
</LinearLayout>
</LinearLayout>
Child.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/child_text"
android:layout_margin="16dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You made it!"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
The idea is that it can achieve share of UI controls. In this case, parent.axml loads child.xml into its place holder based on condition.
You can use LayoutInflater to inflate layouts and auto-attach them to the parent (or not):
var linearLayout = LayoutInflater.Inflate(Resource.Layout.Child, parent, true);
var textView = linearLayout.FindViewById<TextView>(Resource.Id.child_text);
textView.Text = "Inflated and attached to Parent";
Also depending upon your use-case, using a self-contained Fragment and adding that to your "parent" might be better a better solution.

Android Studio,ImageView,shows different size image in different size's mobile

created an android app which loads pics in ImageView randomly from drawable folder by .setImageResource,but the main problem is image it loads shows correct size image but in different size mobile shows different size image,also in some mobile it covers the screen which hides the buttons etc,
its works fine in my Redmi 2 Prime which is 4.7nch,resolution:720*1280,
but in Samsung Galaxy Grand Neo its hides the entire screen with that image i.e screen size: 5.01 inch
resolution: 480*800
Samsung grand neo screenshot  
Redmi 2 screenshot
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4e2f22"
tools:context="com.wordpress.dragontelnetsite.mindreader.SecondActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/backg">
<Button
android:layout_width="140dp"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/button2"
android:onClick="clickedOnPlay2"
android:background="#4cb076"
android:layout_marginBottom="60dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="310dp"
android:layout_height="350dp"
android:id="#+id/chart"
android:scaleType="fitXY"
android:src="#drawable/c1"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>

Animating layout height produces weird flicker

I'm trying to animate a layout (height) placed under the toolbar and inside an AppbarLayout. I have tried several approaches to this: one of them is using ValueAnimator.ofInt and using this int to set the layout's height. This, however, is kind of choppy. According to some posts I've read, it is because requestLayout() is called in each iteration and that's an expensive operation. Almost every other option I've seen requires requestLayout() to be called. Somewhat old devices will not perform well in that case.
The other approach, which apparently is the most efficient, is to simply declare animateLayoutChanges = true in the parent layout (the AppbarLayout in this case) and simply change the height in code. This does work, but it produces and weird jump, as if the layout instantly and very breifly goes to it's final height, collapses again, and then starts animating normally. The same happens when collapsing.
In the activity, I'm simply calling setVisibility(View.VISIBLE) to expand and newTaskLayout.setVisibility(View.GONE) to collapse. I've also tried setting height to 0 and then making the view GONE to collapse, and setting height to wrap content and then making the view VISIBLE to expand, but the result is the same.
Is there any reason for this and way to avoid it? Or is there a better way to do it?
Heres the XML: (The view being animated is the COnstraintLayout under the toolbar)
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.adrapps.mytasks.Views.TaskListActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:title="App"
app:popupTheme="#style/AppTheme.PopupOverlay">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:paddingLeft="8dp"
android:paddingStart="8dp"
android:visibility="gone" />
</android.support.v7.widget.Toolbar>
<android.support.constraint.ConstraintLayout
android:id="#+id/new_task_layout"
android:layout_width="match_parent"
android:layout_height="164dp"
android:paddingBottom="16dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:visibility="visible">
<ImageView
android:id="#+id/title_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="0dp"
android:src="#drawable/ic_label"
app:layout_constraintBottom_toBottomOf="#+id/title_edit_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/title_edit_text"
tools:layout_editor_absoluteX="16dp" />
<ImageView
android:id="#+id/date_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="24dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:src="#drawable/ic_date"
app:layout_constraintBottom_toBottomOf="#+id/date_edit_text"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="#+id/date_edit_text"
app:layout_constraintVertical_bias="0.333" />
<ImageView
android:id="#+id/notification_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="16dp"
android:layout_marginTop="28dp"
android:src="#drawable/ic_notifications_none_black_24dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="#+id/date_icon"
app:layout_constraintTop_toBottomOf="#+id/date_icon" />
<EditText
android:id="#+id/title_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:hint="#string/task_title_hint"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
app:layout_constraintLeft_toRightOf="#+id/title_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="#id/title_icon"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/date_edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="12dp"
android:hint="#string/task_due_date"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="#+id/date_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="#id/date_icon"
app:layout_constraintTop_toBottomOf="#+id/title_edit_text" />
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/notification_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="6dp"
android:entries="#array/notification_options"
app:layout_constraintBottom_toBottomOf="#+id/notification_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="#+id/notification_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/notification_icon" />
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_black_24dp" />
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>

Resources