Design looks perfect on phone but so small on tablet - android studio - android-layout

I made up this xml file for my android project, the design looks perfect on my phone but running it on my tablet makes buttons, images,... look so small, i would love to make their size change according to the device running on.
here's my xml file:
<?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"
android:background="#drawable/background"
android:fitsSystemWindows="true"
tools:context="molfix.dev.molfix.Activities.Bvn.BienvenuActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:background="#91d0f0"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#drawable/toolbar_bvn"
android:scrollbars="none"
app:popupTheme="#style/AppTheme.PopupOverlay"
android:weightSum="1">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<Button
android:layout_width="250dp"
android:layout_height="55dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/button_inscrip"
android:id="#+id/b_inscrip"
android:layout_marginTop="20dp"
android:layout_below="#+id/b_connex"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="250dp"
android:layout_height="55dp"
android:background="#drawable/button_connex"
android:id="#+id/b_connex"
android:layout_marginTop="151dp"
android:layout_below="#+id/appbar"
android:layout_alignStart="#+id/b_inscrip" />
</RelativeLayout>

You can try scalable dp instead of dp/sp etc. This will adjust the size of views according to device running on.
Dependency:-
compile 'com.intuit.sdp:sdp-android:1.0.2'
Use like this:-
Replace all "10dp" (your dp value) with "dimen/_10sdp" (change according to your dp value) in your xml.

You have to design your xmls for multi screens. For tab supported, you should create layout-sw600dp layout, this will support 7 inch tablets and for 10 inch tablet create layout-sw720dp. After creating those layouts in res folder copy and paste your xmls in that folders and give sizes for views according to your requirement.

Related

What are differents for Tab UI between BottomNavigationView and TabLayout in Android Studio 4.0?

The Code A and Image A are from the project architecture-components-samples .
The Code B and Image B are from the project sunflower.
The Code A use com.google.android.material.bottomnavigation.BottomNavigationView to implement Tab UI.
The Code B use com.google.android.material.tabs.TabLayout to implement Tab UI.
It seems that the two controls can do the same things.
What are differents for Tab UI between BottomNavigationView and TabLayout in Android Studio 4.0?
Code A
<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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.navigationadvancedsample.MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/bottom_nav"/>
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
Code B
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/Theme.Sunflower.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|snap"
app:toolbarId="#id/toolbar">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
style="#style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax">
<TextView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center"
android:text="#string/app_name"
android:textAppearance="?attr/textAppearanceHeadline5" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<!-- Override tabIconTint attribute of style with selector -->
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
style="#style/Widget.MaterialComponents.TabLayout.Colored"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabIconTint="#drawable/tab_icon_color_selector"
app:tabTextColor="?attr/colorPrimaryDark"/>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
Image A
Image B
There are some subtle UX differences between the two, but here's a summary of when to use them from the Material UI design guidelines:
Bottom navigation bars allow movement between primary destinations in an app
...
Bottom navigation should be used for:
Top-level destinations that need to be accessible from anywhere in the app
Three to five destinations
Mobile or tablet only
Bottom navigation shouldn’t be used for:
Single tasks, such as viewing a single email
User preferences or settings
Also note these guidelines:
You can read more about when to use Tabs vs Bottom Navigation at the Material Design site.

How to add XML Google Pay Button in Flutter

My Flutter app uses Google Pay as a payment method. Following these guidelines, they provide XML buttons (which I have never dealt with).
How can I add one of these button to a flutter widget using dart?
There are different implementations for laying out content for Android versus Flutter.
The layout/googlepay_button.xml layout effectively describes the way the button appears, and drawable/googlepay_button_content.xml contains VectorDrawable file for the Google Pay button. flutter_svg should help you render the contents of the image.
To get this to work with Flutter, you would need to reproduce the xml layout as a Flutter widget tree.
Sample layout black/res/layout/googlepay_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="48sp"
android:background="#drawable/googlepay_button_no_shadow_background"
android:paddingTop="2sp"
android:contentDescription="#string/googlepay_button_content_description">
<LinearLayout
android:duplicateParentState="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:duplicateParentState="true"
android:src="#drawable/googlepay_button_content"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:duplicateParentState="true"
android:src="#drawable/googlepay_button_overlay"/>
</RelativeLayout>
It looks like SVG. Try to open all these XML files like SVG, and add it to assets folder in your project.

I have a layout that contains relative layout with two vertical linear layouts that displays on a zebra MC67

But the same activity blows up loading on a zebra m6000. Let me state that I am a novice using Android Studio and Java. I have been a VB programmer for many years.
The XML has 2 includes. One foe each vertical linear layout. I can add the XML's for them if needed.
What could cause the rendering to work on one android device (which is running an earlier version of OS ) but fail on newer device.
Here is 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"
android:background="#color/colorBackgroundGray"
tools:context="com.procatdt.stockright.activities.PutAwayAreaActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<include
android:id="#+id/include2"
layout="#layout/frm1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="left" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:orientation="vertical">
<include
android:id="#+id/include"
layout="#layout/layout_numpad5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="220dp"
android:layout_weight="1"
android:layout_gravity="right"
/>
</LinearLayout>
</RelativeLayout>
Here is how it is rendering on MC67
Found Issue. One of the Buttons in my include was the culprit. KitKat didn't care but lollipop didn't like the backgroundtint value.
Looking through logcat I saw culprit was a button and from there it was process of elimination.

In Android Studio the widgets are moving up on the screen during emulation

I am new to both Stack Overflow and Android Studio and learning to code now.
I did a basic user and password layout in Android Studio like this:
When I ran this on emulator, it displays the widgets like this:
I tried to change the width of the EditText fields, buttons, but nothing I have tried seems to be working.
How do I solve this?
What am I missing or am I doing something wrong ?
Layout code:
<?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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="233dp"
android:scaleType="fitStart"
android:visibility="visible"
app:srcCompat="#drawable/worldcurrency" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter ammount"
android:textSize="18sp" />
<EditText
android:id="#+id/dollar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="convert"
android:text="Convert" />
<TextView
android:id="#+id/rupees"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Your layout's parent is a ConstraintLayout, but it's lacking every constraint. ConstraintLayout is characterised by the ability to set constraints to every view, forcing its behaviour across screens of different sizes and orientations.
If you really want to use a ConstraintLayout I suggest taking a look at the ConstraintLayout Documentation. Once you've properly set the constraints, you should have an xml like this (note the constraint* attributes in my Views.
So, your layout has no constraints, it's likely it will end at "random" positions. Moreover, you've set the views coordinates with tools, which is valid only for the layout preview, not for runtime. And moreover, the use of absolute coordinates is very not recommended, since it can cause problems across different screen sizes.
If ConstraintLayout is an optional choice for you, you can change the layout parent to a LinearLayout with vertical orientation, I think it's more suitable for the layout you're building (I'm assuming this by your screenshots).Hope I helped, let me know. Good luck and happy coding!

How Can I Reduced The Padding of My Toolbar

Good day, can you help me with this one?
I add icons on my toolbar, the problem is, it took too much space.
How can I reduced them? To look Like this one below
minTarget is - 15 to 23 present.
Here's my code:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:layout_margin="0dp"
android:padding="0dp"
android:minHeight="?android:attr/actionBarSize"
android:background="#color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp" />

Resources