Android studio icon anc text scale - java

I try to make my application for different resolution and screen size. For layouts I use weights and it works perfectly but have problem with texts and icons (Vector Assets in androidstudio). Actually I use constant value for texts(e.g 20sp) and icons(e.g 20dp) but when application is open in another mobile icons are too small or too big. Is it possible to scale it by screen size in xml file?
<LinearLayout 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.hgyghyfghyu.apkana40.TrainerMenu"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp">
//
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#000000"
android:layout_marginBottom="10dp"
android:id="#+id/colorsdialogbtn">
</LinearLayout>
//
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
//
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000000"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/trainermenugroupsbtn">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trainermenugroupsicon"
android:tint="#FFFFFF"
android:layout_centerInParent="true"
android:src="#drawable/trainermenugroupsicon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/trainermenugroupsicon"
android:textSize="25dp"
android:textStyle="bold"
android:text=""
android:textColor="#FFFFFF"/>
</RelativeLayout>
</LinearLayout>
//
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000000"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="#+id/trainermenutrainersbtn">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/trainermenutrainersicon"
android:tint="#FFFFFF"
android:layout_centerInParent="true"
android:src="#drawable/trainermenutrainersicon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/trainermenutrainersicon"
android:textSize="25dp"
android:textStyle="bold"
android:text=""
android:textColor="#FFFFFF"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
//
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
//
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#000000"
android:id="#+id/trainermenuadbtn"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp">
<ImageView
android:id="#+id/trainermenuadicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#FFFFFF"
android:src="#drawable/trainermenuadicon"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/trainermenuadicon"
android:layout_centerHorizontal="true"
android:textSize="15dp"
android:text=""
android:textStyle="bold"
android:textColor="#FFFFFF"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
//info
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000000"
android:id="#+id/trainermenuinfobtn"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#FFFFFF"
android:src="#drawable/trainermenuinfoicon"
android:layout_centerInParent="true"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000000"
android:id="#+id/trainermenusettingsbtn"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="#FFFFFF"
android:layout_centerInParent="true"
android:src="#drawable/trainermenusettingicon"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

Related

Align text in RecyclerView with titles

Hello I have made a RecyclerView with orders. But the list in the popup isnt't aligned with the titles. Because pictures say more than words, here you can see it:
But what I need is something like that:
How could I make this work? How can I nicely define the columns so that each article fits nicely under the heading?
Here is my RecyclerView:
<?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="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:id="#+id/order_overview_artikel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Artikel"
android:layout_marginRight="10dp"
android:textSize="16dp"/>
<TextView
android:id="#+id/order_overview_anzahl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anzahl"
android:layout_marginRight="10dp"
android:textSize="16dp"/>
<TextView
android:id="#+id/order_overview_preis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preis"
android:textSize="16dp"/>
</LinearLayout>
And this is the pop up:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Bestellübersicht"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold"></TextView>
<TextView
android:id="#+id/order_overview_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="0"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:text="Produkt"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Anzahl"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Preis"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview_order_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.airbnb.lottie.LottieAnimationView
android:layout_width="match_parent"
android:layout_height="128dp"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="#raw/walkingburger" />
<Button
android:id="#+id/btn_order_overview_finish"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:background="#drawable/button_order_checkout"
android:backgroundTint="#9BC3BF"
android:elevation="16dp"
android:text="FERTIG"
android:textColor="#FFFFFF"
android:textStyle="bold"
app:layout_constraintVertical_bias="0.777" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
You need to use a similar layout pattern for title layout and the recycler view item. It's
use
android:weightSum="3"
and for child views set the layout_weight as 1. All three will be aligned.
I have made changes to your code.
RecyclerView Item
<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="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:gravity="center">
<TextView
android:id="#+id/order_overview_artikel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Artikel"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="10dp"
android:textSize="16dp"/>
<TextView
android:id="#+id/order_overview_anzahl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anzahl"
android:layout_weight="1"
android:gravity="center"
android:layout_marginRight="10dp"
android:textSize="16dp"/>
<TextView
android:id="#+id/order_overview_preis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preis"
android:gravity="center"
android:layout_weight="1"
android:textSize="16dp"/>
</LinearLayout>
Your popup
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Bestellübersicht"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold"></TextView>
<TextView
android:id="#+id/order_overview_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="0"
android:textAlignment="center"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:weightSum="3"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:text="Produkt"
android:layout_weight="1"
android:gravity="center"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Anzahl"
android:layout_weight="1"
android:gravity="center"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="Preis"
android:layout_weight="1"
android:gravity="center"
android:textAlignment="center"
android:textSize="18dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview_order_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.airbnb.lottie.LottieAnimationView
android:layout_width="match_parent"
android:layout_height="128dp"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="#raw/walkingburger" />
<Button
android:id="#+id/btn_order_overview_finish"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:background="#drawable/button_order_checkout"
android:backgroundTint="#9BC3BF"
android:elevation="16dp"
android:text="FERTIG"
android:textColor="#FFFFFF"
android:textStyle="bold"
app:layout_constraintVertical_bias="0.777" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
First of all, in your pop, for "Produkt", "Anzahl" and etc. you write layout_width like "match_parent", but in your RecyclerView layout_width of items is wrap_content. Change layout_width on match_parent in your RecyclerView.
You need a table view layout in order to align texts, you can also use linear layout but it tricky and complex UI solution which performs quite heavy operations on the UI layer to render (example using weights in linear layout).
Check this android official link for more understanding.

Android Java fragment is displayed on half screen

I have developing android app.
I have problem when displaying list of card in recycler-view that within in fragment_auction_products.xml.
When I navigate to FragmentAuctionProducts, I have the
this is the problem
As you can see my list starts showing after 50% space is empty... How I can solve this?
My fragment_auction_products.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/home_auction_products_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginTop="10dp"/>
<ProgressBar
android:id="#+id/home_auction_products_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateDrawable="#drawable/spinner_ring"
android:indeterminateOnly="true" />
</LinearLayout>
My recycler view item:
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp"
android:gravity="center"
android:background="#drawable/layer_shadow"
android:orientation="horizontal">
<ImageView
android:id="#+id/home_auction_products_recycler_view_image"
android:layout_margin="4dp"
android:layout_width="125dp"
android:layout_height="150dp"
android:src="#drawable/card_example_1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginStart="15dp"
android:layout_marginEnd="10dp"
android:orientation="vertical"
android:paddingTop="15dp">
<TextView
android:id="#+id/home_auction_products_recycler_view_title"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/muli_bold"
android:text="Title"
android:textColor="#color/colorBlack"
android:textSize="14dp" />
<TextView
android:id="#+id/home_auction_products_recycler_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/muli_bold"
android:text="id"
android:textColor="#color/colorBlack"
android:textSize="0dp" />
<TextView
android:id="#+id/home_auction_products_recycler_view_current_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/muli_bold"
android:text="50000 тг"
android:textColor="#color/colorTextYellow"
android:textSize="16dp" />
<TextView
android:id="#+id/home_auction_products_recycler_view_start_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/muli"
android:text="start-price"
android:textColor="#color/colorBlack"
android:textSize="12dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:background="#drawable/auction_products_shape"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingTop="2dp"
android:paddingRight="4dp"
android:paddingBottom="2dp">
<TextView
android:id="#+id/home_auction_products_recycler_view_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/muli"
android:gravity="center"
android:text="10"
android:textColor="#color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/muli"
android:gravity="center"
android:text="ДНЕЙ"
android:textColor="#color/colorWhite"
android:textSize="6dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/auction_products_shape"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingTop="2dp"
android:paddingRight="4dp"
android:paddingBottom="2dp">
<TextView
android:id="#+id/home_auction_products_recycler_view_hour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/muli"
android:gravity="center"
android:text="12"
android:textColor="#color/colorWhite"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="#font/muli"
android:gravity="center"
android:text="ЧАСОВ"
android:textColor="#color/colorWhite"
android:textSize="6dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal">
<TextView
android:id="#+id/home_auction_products_recycler_view_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_mdi_keyboard_arrow_right"
android:fontFamily="#font/muli"
android:textColor="#color/colorTextGray"
android:textSize="12dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
My main container where I call my fragments:
<?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/colorWhite"
tools:context=".activity.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/bottom_nav_bar">
<FrameLayout
android:id="#+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="?android:windowBackground"
app:menu="#menu/menu" />
</RelativeLayout>
Change the FrameLayout height to match_parent.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottom_nav_bar">
<FrameLayout
android:id="#+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
Just use android:layout_alignParentTop.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/home_auction_products_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginTop="10dp"/>
<ProgressBar
android:id="#+id/home_auction_products_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateDrawable="#drawable/spinner_ring"
android:indeterminateOnly="true" />
</LinearLayout>
Hope this helps.

What type of padding do I need to use in Android studio to center my buttons on the screen?

I'm trying to adjust the home screen on my app to move the buttons slightly to the right.
Here's a link to an image version of my current home screen.
Here's what I want it to look like:
All the icons I uploaded have extra room on them to adjust for the padding.I made the icons on sketch and uploaded them as entire buttons.
Here's a screenshot of one of them:
I know I need to do something with padding, but what should I write to ensure that icons and text are shifted to the right.
Here's the activity in question:
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="com.example.leoconnelly.connexus.MainActivity">
<LinearLayout
android:id="#+id/ll_learn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/learn"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/learn_layer_long"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:padding="0dp"
android:layout_weight="1"
android:text="#string/learn"
android:textSize="22sp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_find_care"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical">
<ImageButton
android:id="#+id/find_care_button"
android:layout_width="match_parent"
android:padding = "0dp"
android:scaleType="centerCrop"
android:src="#mipmap/findcare_layer_long"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="#string/learn"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_talk_to_doctor"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical">
<ImageButton
android:id="#+id/TalkToADocButton"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/talk_doc_layer_long"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:padding="0dp"
android:layout_weight="1"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_visit_website"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical">
<ImageButton
android:id="#+id/VisitWeb"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/visit_web_layer_long"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:padding="0dp"
android:layout_weight="1"
android:textSize="22sp" />
</LinearLayout>
Try it:
<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:id="#+id/ll_learn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:src="#mipmap/findcare_layer_long"
android:scaleType="centerCrop"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:text="#android:string/untitled"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_find_care"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:src="#mipmap/findcare_layer_long"
android:scaleType="centerCrop"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:text="#android:string/untitled"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_talk_to_doctor"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:src="#mipmap/talk_doc_layer_long"
android:scaleType="centerCrop"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:text="#android:string/untitled"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_visit_website"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:src="#mipmap/visit_web_layer_long"
android:scaleType="centerCrop"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:text="#android:string/untitled"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="22sp" />
</LinearLayout>
</LinearLayout>
Set your padding within your parent layout. So if you want a padding for all of your 4 sides of "5dp", you will do the following:
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
tools:context="com.example.leoconnelly.connexus.MainActivity">
Here I have customized your layout file.
<?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:id="#+id/ll_learn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#android:color/holo_blue_light">
<TextView
android:id="#+id/learn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:drawablePadding="30dp"
android:drawableStart="#drawable/ic_ico"
android:gravity="center_vertical|center_horizontal"
android:scaleType="centerCrop"
android:text="learn"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_find_care"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#android:color/holo_green_dark">
<TextView
android:id="#+id/find_care"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:drawablePadding="30dp"
android:drawableStart="#drawable/ic_ico"
android:gravity="center_vertical|center_horizontal"
android:scaleType="centerCrop"
android:text="Find Care"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_talk_to_doctor"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#android:color/holo_orange_dark">
<TextView
android:id="#+id/TalkToADocButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:drawablePadding="30dp"
android:drawableStart="#drawable/ic_ico"
android:gravity="center_vertical|center_horizontal"
android:scaleType="centerCrop"
android:text="Emergency"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_visit_website"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#android:color/holo_red_dark">
<TextView
android:id="#+id/VisitWeb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:drawablePadding="30dp"
android:drawableStart="#drawable/ic_ico"
android:gravity="center_vertical|center_horizontal"
android:scaleType="centerCrop"
android:text="Message to a Doctor"
android:textStyle="bold"
android:textColor="#color/white"
android:textSize="30sp" />
</LinearLayout>
Note: Change colors and icons as per your requirements. Because here I have used sample image and colors for testing purpose.
Output:

Android Align LinearLayout at Bottom not Working

I have this LinearLayout and in it is a Map Fragment and this all works but I cannot get the linear layout to align to the bottom of the screen for some reason. Here is my xml:
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity"
android:baselineAligned="false"
android:weightSum="1"
android:background="#mipmap/background_colour">
<LinearLayout
android:orientation="vertical"
android:layout_width="30dp"
android:layout_height="31dp"
android:weightSum="1"
android:id="#+id/back_button"
android:background="#drawable/navigation_back"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.31">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView7" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.30">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView6" />
</LinearLayout>
<LinearLayout
android:id="#+id/lay"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_weight="3.5">
</LinearLayout>
</LinearLayout>
The LinearLayout I am trying to align is the id: "lay" one.
I found a fix:
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity"
android:baselineAligned="false"
android:weightSum="1"
android:background="#mipmap/background_colour">
<LinearLayout
android:orientation="vertical"
android:layout_width="30dp"
android:layout_height="31dp"
android:weightSum="1"
android:id="#+id/back_button"
android:background="#drawable/navigation_back"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="177dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView7" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="146dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView6" />
</LinearLayout>
<LinearLayout
android:id="#+id/lay"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="match_parent">
</LinearLayout>
</LinearLayout>

lag when scrolling activity

In my applications main activity I have 19 images with textview under them in a NestedScrollView. Images size is about 25 KB and when I run application on LG G3 it has lag. What can I do? And caching images can help me?
XML file:
<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:context="ir.aftabeshafa.shafadoc.MainActivity"
tools:showIn="#layout/app_bar_main">
<android.support.v4.widget.NestedScrollView
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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView"
android:src="#mipmap/brain" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/brain"
android:id="#+id/textView"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView2"
android:src="#mipmap/dentist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/dentist"
android:id="#+id/textView2"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView3"
android:src="#mipmap/dermatologist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/dermatologist"
android:id="#+id/textView3"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView4"
android:src="#mipmap/digestive" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/digestive"
android:id="#+id/textView4"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView5"
android:src="#mipmap/ent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/ent"
android:id="#+id/textView5"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView6"
android:layout_marginTop="8dp"
android:src="#mipmap/eye" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/eye"
android:id="#+id/textView6"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView7"
android:src="#mipmap/general" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/general"
android:id="#+id/textView7"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView8"
android:src="#mipmap/gynecologist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/gynecologist"
android:id="#+id/textView8"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView9"
android:src="#mipmap/heart" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/heart"
android:id="#+id/textView9"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView10"
android:src="#mipmap/infection" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/infection"
android:id="#+id/textView10"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView11"
android:src="#mipmap/inner" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/inner"
android:id="#+id/textView11"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="96dp"
android:layout_height="96dp"
android:id="#+id/imageView12"
android:src="#mipmap/kidney" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/kidney"
android:id="#+id/textView12"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
Your layout is too complex. You have a RelativeLayout as root element (bad idea), which only has 1 child (a NestedScrollView) - your RelativeLayout is redundant and only causing unnecessary churn.
Start by removing the RelativeLayout and make your ScrollView the top layout. See if you can streamline the rest of the layout by using a TextView with drawableLeft instead of having a TextView and Imageview.
Instead of loading everything from the get go, you could consider using a RecyclerView and load only a subset of the images, and let your adapter load more as the user scrolls.

Categories

Resources